From 1743dce64d00278f56b395a4250ea460707e0a55 Mon Sep 17 00:00:00 2001 From: wangxinbo Date: Wed, 21 May 2025 09:12:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:PackageStructureKit=20FAQ=20=E6=95=B4?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/a_app_module.json5 | 65 +++++++++++++++++++ .../entry/src/main/b_app_module.json5 | 61 +++++++++++++++++ .../entry/src/main/ets/pages/IndexA.ets | 61 +++++++++++++++++ .../resources/base/profile/main_pages.json | 5 +- 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 PackageStructureKit/entry/src/main/a_app_module.json5 create mode 100644 PackageStructureKit/entry/src/main/b_app_module.json5 create mode 100644 PackageStructureKit/entry/src/main/ets/pages/IndexA.ets diff --git a/PackageStructureKit/entry/src/main/a_app_module.json5 b/PackageStructureKit/entry/src/main/a_app_module.json5 new file mode 100644 index 0000000..73191e1 --- /dev/null +++ b/PackageStructureKit/entry/src/main/a_app_module.json5 @@ -0,0 +1,65 @@ +/* +* FAQ:如何判断应用程序是否安装 + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ], + // [Start a_app_module] + "uris": [ + { + "scheme":"schB", + "host":"com.example.test", + "path":"open", + } + ], + // [End a_app_module] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PackageStructureKit/entry/src/main/b_app_module.json5 b/PackageStructureKit/entry/src/main/b_app_module.json5 new file mode 100644 index 0000000..56a59c3 --- /dev/null +++ b/PackageStructureKit/entry/src/main/b_app_module.json5 @@ -0,0 +1,61 @@ +/* +* FAQ:如何判断应用程序是否安装 + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + // [Start b_app_module] + "querySchemes": [ + "schB" + ], + // [End b_app_module] + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/PackageStructureKit/entry/src/main/ets/pages/IndexA.ets b/PackageStructureKit/entry/src/main/ets/pages/IndexA.ets new file mode 100644 index 0000000..f33d7b3 --- /dev/null +++ b/PackageStructureKit/entry/src/main/ets/pages/IndexA.ets @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何判断应用程序是否安装 + */ + +// [Start is_app_b_exist] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { bundleManager } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +@Entry +@Component +struct Index { + // Application A determines whether Application B is installed on the device + isAppBExist() { + let exist = false; + try { + let link = 'schB://com.example.test/open'; + let data: boolean = bundleManager.canOpenLink(link); + hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data)); + exist = data; + } catch (err) { + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message); + exist = false; + } + console.info('Has application B been installed:' + exist); + } + + @State text: string = 'isAppBExist' + + build() { + Row() { + Column() { + Text(this.text) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.isAppBExist(); + }); + } + .width('100%') + } + .height('100%') + } +} +// [End is_app_b_exist] \ No newline at end of file diff --git a/PackageStructureKit/entry/src/main/resources/base/profile/main_pages.json b/PackageStructureKit/entry/src/main/resources/base/profile/main_pages.json index 1898d94..cce56d0 100644 --- a/PackageStructureKit/entry/src/main/resources/base/profile/main_pages.json +++ b/PackageStructureKit/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,6 @@ { "src": [ - "pages/Index" + "pages/Index", + "pages/IndexA" ] -} +} \ No newline at end of file -- Gitee