From b45aca946df4cfd7589b31b2d7613c30130362a7 Mon Sep 17 00:00:00 2001 From: geng-wenguang Date: Fri, 6 Jan 2023 17:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=85=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: geng-wenguang --- .../reference/apis/js-apis-bundleManager.md | 740 +++++++++--------- 1 file changed, 362 insertions(+), 378 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md b/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md index 0651040d7b..d070bd7a33 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-bundleManager.md @@ -2,14 +2,15 @@ 本模块提供应用信息查询能力,支持BundleInfo、ApplicationInfo、Ability、ExtensionAbility等信息的查询 -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> **说明:** > 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; ``` + ## 权限列表 | 权限 | 权限等级 | 描述 | @@ -27,7 +28,7 @@ import bundleManager from '@ohos.bundle.bundleManager' 包信息标志,指示需要获取的包信息的内容。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 | 值 | 说明 | | ----------------------------------------- | ---------- | ------------------------------------------------------------ | @@ -45,7 +46,7 @@ import bundleManager from '@ohos.bundle.bundleManager' 应用信息标志,指示需要获取的应用信息的内容。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 **系统接口:** 系统接口,不支持三方应用调用。 @@ -58,9 +59,9 @@ import bundleManager from '@ohos.bundle.bundleManager' ### AbilityFlag -功能组件信息标志,指示需要获取的功能组件信息的内容。 +Ability组件信息标志,指示需要获取的Ability组件信息的内容。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 **系统接口:** 系统接口,不支持三方应用调用。 @@ -77,7 +78,7 @@ import bundleManager from '@ohos.bundle.bundleManager' 扩展组件信息标志,指示需要获取的扩展组件信息的内容。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 **系统接口:** 系统接口,不支持三方应用调用。 @@ -92,7 +93,7 @@ import bundleManager from '@ohos.bundle.bundleManager' 指示扩展组件的类型。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 | 值 | 说明 | |:----------------:|:---:|-----| @@ -115,9 +116,9 @@ import bundleManager from '@ohos.bundle.bundleManager' ### PermissionGrantState -指示权限授予信息。 +指示权限授予状态。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 | 值 | 说明 | |:----------------:|:---:|:---:| @@ -128,7 +129,7 @@ import bundleManager from '@ohos.bundle.bundleManager' 标识该组件所支持的窗口模式。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 | 值 | 说明 | |:----------------:|:---:|:---:| @@ -140,21 +141,21 @@ import bundleManager from '@ohos.bundle.bundleManager' 指示组件的启动方式。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 | 值 | 说明 | |:----------------:|:---:|:---:| -| SINGLETON | 0 | ability的启动模式,表示单实例。 | -| STANDARD | 1 | ability的启动模式,表示普通多实例。 | -| SPECIFIED | 2 | ability的启动模式,表示该ability内部根据业务自己置顶多实例。 | +| SINGLETON | 0 | ability的启动模式,表示单实例。 | +| STANDARD | 1 | ability的启动模式,表示普通多实例。 | +| SPECIFIED | 2 | ability的启动模式,表示该ability内部根据业务自己置顶多实例。 | ### AbilityType 指示Ability组件的类型。 - **模型约束:** 仅可在FA模型下使用 + **模型约束:** 仅可在FA模型下使用 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 | 值 | 说明 | | :-----: | ---- | :--------------------------------------------------------: | @@ -166,7 +167,7 @@ import bundleManager from '@ohos.bundle.bundleManager' 标识该Ability的显示模式。该标签仅适用于page类型的Ability。 - **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 + **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 | 名称 |值 |说明 | |:----------------------------------|---|---| @@ -184,7 +185,7 @@ import bundleManager from '@ohos.bundle.bundleManager' | AUTO_ROTATION_PORTRAIT_RESTRICTED |11|表示受开关控制的自动竖向旋转模式。| | LOCKED |12|表示锁定模式。| -## 方法 +## 接口 ### bundleManager.getBundleInfoForSelf @@ -209,16 +210,17 @@ getBundleInfoForSelf(bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo]( **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; try { bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { - console.info('getBundleInfoForSelf successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); }).catch(error => { - console.error('getBundleInfoForSelf failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', error.message); }); } catch (error) { - console.error('getBundleInfoForSelf failed:' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', error.message); } ``` @@ -240,19 +242,20 @@ getBundleInfoForSelf(bundleFlags: [number](#bundleflag), callback: AsyncCallback **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; try { bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => { if (err) { - console.error('getBundleInfoForSelf failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', error.message); } else { - console.info('getBundleInfoForSelf successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data)); } }); } catch (err) { - console.error('getBundleInfoForSelf failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', error.message); } ``` @@ -272,7 +275,7 @@ getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------ | ---- | ---------------------------- | -| bundleName | string | 是 | 表示要查询的应用程序包名称。 | +| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | | bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。| | userId | number | 是 | 表示用户ID。 | | callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的bundleInfo;否则为错误对象。 | @@ -291,7 +294,8 @@ getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: ```ts // 额外获取AbilityInfo -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY; let userId = 100; @@ -299,19 +303,20 @@ let userId = 100; try { bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { if (err) { - console.error('getBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message); } else { - console.info('getBundleInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message); } ``` ```ts // 额外获取ApplicationInfo中的metadata -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; let userId = 100; @@ -319,13 +324,13 @@ let userId = 100; try { bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { if (err) { - console.error('getBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message); } else { - console.info('getBundleInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message); } ``` @@ -345,7 +350,7 @@ getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\< | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------ | ---- | ---------------------------- | -| bundleName | string | 是 | 表示要查询的应用程序包名称。 | +| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | | bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。| | callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | @@ -363,20 +368,21 @@ getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\< ```ts // 额外获取extensionAbility -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; try { bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => { if (err) { - console.error('getBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message); } else { - console.info('getBundleInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message); } ``` @@ -396,7 +402,7 @@ getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: n | 参数名 | 类型 | 必填 | 说明 | | ----------- | ------ | ---- | ---------------------------- | -| bundleName | string | 是 | 表示要查询的应用程序包名称。 | +| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | | bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | | userId | number | 否 | 表示用户ID。 | @@ -420,35 +426,37 @@ getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: n ```ts // 额外获取ApplicationInfo和SignatureInfo -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; let userId = 100; try { bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => { - console.info('getBundleInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getBundleInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getBundleInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message); } ``` ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; try { bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => { - console.info('getBundleInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getBundleInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getBundleInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message); } ``` @@ -469,7 +477,7 @@ getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), use | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------ | ---- | ---------------------------- | -| bundleName | string | 是 | 表示要查询的应用程序包名称。 | +| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | | appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | | userId | number | 是 | 表示用户ID。 | | callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | @@ -487,7 +495,8 @@ getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), use **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; let userId = 100; @@ -495,13 +504,13 @@ let userId = 100; try { bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => { if (err) { - console.error('getApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message); } else { - console.info('getApplicationInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message); } ``` @@ -521,7 +530,7 @@ getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), cal | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------ | ---- | ---------------------------- | -| bundleName | string | 是 | 表示要查询的应用程序包名称。 | +| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | | appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | | callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | @@ -538,20 +547,21 @@ getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), cal **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; try { bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => { if (err) { - console.error('getApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message); } else { - console.info('getApplicationInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message); } ``` @@ -571,7 +581,7 @@ getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), use | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------ | ---- | ---------------------------- | -| bundleName | string | 是 | 表示要查询的应用程序包名称。 | +| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | | appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | | userId | number | 否 | 表示用户ID。 | @@ -594,19 +604,20 @@ getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), use **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; let userId = 100; try { bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => { - console.info('getApplicationInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getApplicationInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getApplicationInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s' + err.message); } ``` @@ -614,7 +625,7 @@ try { getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: AsyncCallback>): void; -以异步方法根据给定的bundleFlags和userId获取多个BundleInfo,使用callback形式返回结果。 +以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -641,20 +652,21 @@ getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: A **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; let userId = 100; try { bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => { if (err) { - console.error('getAllBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s' + err.message); } else { - console.info('getAllBundleInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getAllBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s' + err.message); } ``` @@ -662,7 +674,7 @@ try { getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback>): void; -以异步方法根据给定的bundleFlags获取多个BundleInfo,使用callback形式返回结果。 +以异步方法根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -688,19 +700,20 @@ getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback { if (err) { - console.error('getAllBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s' + err.message); } else { - console.info('getAllBundleInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getAllBundleInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s' + err.message); } ``` @@ -708,7 +721,7 @@ try { getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise>; -以异步方法根据给定的bundleFlags和userId获取多个BundleInfo,使用Promise形式返回结果。 +以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -740,17 +753,18 @@ getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise { - console.info('getAllBundleInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getAllBundleInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getAllBundleInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s' + err.message); } ``` @@ -758,7 +772,7 @@ try { getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback>): void; -以异步方法根据给定的appFlags和userId获取多个ApplicationInfo,使用callback形式返回结果。 +以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -785,20 +799,21 @@ getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, call **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; let userId = 100; try { bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => { if (err) { - console.error('getAllApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s' + err.message); } else { - console.info('getAllApplicationInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getAllApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s' + err.message); } ``` @@ -806,7 +821,7 @@ try { getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallback>): void; -以异步方法根据给定的appFlags获取多个ApplicationInfo,使用callback形式返回结果。 +以异步方法根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -832,19 +847,20 @@ getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallb **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; try { bundleManager.getAllApplicationInfo(appFlags, (err, data) => { if (err) { - console.error('getAllApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s' + err.message); } else { - console.info('getAllApplicationInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getAllApplicationInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s' + err.message); } ``` @@ -852,7 +868,7 @@ try { getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Promise>; -以异步方法根据给定的appFlags和userId获取多个ApplicationInfo,使用Promise形式返回结果。 +以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -884,17 +900,18 @@ getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Pr **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; try { bundleManager.getAllApplicationInfo(appFlags).then((data) => { - console.info('getAllApplicationInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getAllApplicationInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getAllApplicationInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s' + err.message); } ``` @@ -915,7 +932,7 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: numbe | 参数名 | 类型 | 必填 | 说明 | | ------------ | ------ | ---- | ------------------------------------------------------- | -| want | Want | 是 | 表示包含要查询的应用程序包名称的Want。 | +| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | | abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | | userId | number | 是 | 表示用户ID。 | | callback | AsyncCallback> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\;否则为错误对象。 | @@ -935,7 +952,8 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: numbe **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let userId = 100; let want = { @@ -946,13 +964,13 @@ let want = { try { bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => { if (err) { - console.error('queryAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message); } else { - console.info('queryAbilityInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('queryAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message); } ``` @@ -972,7 +990,7 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: Asy | 参数名 | 类型 | 必填 | 说明 | | ------------ | ------ | ---- | -------------------------------------------------------| -| want | Want | 是 | 表示包含要查询的应用程序包名称的Want。 | +| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | | abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | | callback | AsyncCallback> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\;否则为错误对象。 | @@ -991,7 +1009,8 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: Asy **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let want = { bundleName : "com.example.myapplication", @@ -1001,13 +1020,13 @@ let want = { try { bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => { if (err) { - console.error('queryAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message); } else { - console.info('queryAbilityInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('queryAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message); } ``` @@ -1027,7 +1046,7 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: numb | 参数名 | 类型 | 必填 | 说明 | | ------------ | ------ | ---- | ------------------------------------------------------- | -| want | Want | 是 | 表示包含要查询的应用程序包名称的Want。 | +| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | | abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | | userId | number | 否 | 表示用户ID。 | @@ -1052,7 +1071,8 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: numb **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let userId = 100; let want = { @@ -1062,17 +1082,18 @@ let want = { try { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => { - console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); } ``` ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let want = { bundleName : "com.example.myapplication", @@ -1081,12 +1102,12 @@ let want = { try { bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => { - console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); }) } catch (error) { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1106,10 +1127,10 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp | 参数名 | 类型 | 必填 | 说明 | | --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| want | Want | 是 | 表示包含要查询的应用程序包名称的Want。 | -| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | -| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | -| userId | number | 是 | 表示用户ID。 | +| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | +| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | +| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | +| userId | number | 是 | 表示用户ID。 | | callback | AsyncCallback> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\;否则为错误对象。 | **错误码:** @@ -1126,7 +1147,8 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let userId = 100; @@ -1138,13 +1160,13 @@ let want = { try { bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => { if (err) { - console.error('queryExtensionAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message); } else { - console.info('queryExtensionAbilityInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('queryExtensionAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message); } ``` @@ -1164,9 +1186,9 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp | 参数名 | 类型 | 必填 | 说明 | | --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| want | Want | 是 | 表示包含要查询的应用程序包名称的Want。 | -| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | -| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | +| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | +| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | +| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | | callback | AsyncCallback> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\;否则为错误对象。 | **错误码:** @@ -1183,7 +1205,8 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let want = { @@ -1194,13 +1217,13 @@ let want = { try { bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => { if (err) { - console.error('queryExtensionAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message); } else { - console.info('queryExtensionAbilityInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('queryExtensionAbilityInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message); } ``` @@ -1218,9 +1241,9 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| --------------------- | --------------------------------------------- | ---- | ------------------------------------------------------- | -| want | Want | 是 | 表示包含要查询的应用程序包名称的Want。 | +| 参数名 | 类型 | 必填 | 说明 | +| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | +| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | | extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | | extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | | userId | number | 否 | 表示用户ID。 | @@ -1245,7 +1268,8 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; @@ -1257,17 +1281,18 @@ let want = { try { bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => { - console.info('queryExtensionAbilityInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message); } ``` ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let want = { @@ -1277,12 +1302,12 @@ let want = { try { bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => { - console.info('queryExtensionAbilityInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message); }) } catch (error) { - console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1290,7 +1315,7 @@ try { getBundleNameByUid(uid: number, callback: AsyncCallback\): void; -以异步方法根据给定的uid获取bundleName,使用callback形式返回结果。 +以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1316,18 +1341,19 @@ getBundleNameByUid(uid: number, callback: AsyncCallback\): void; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let uid = 20010005; try { bundleManager.getBundleNameByUid(uid, (err, data) => { if (err) { - console.error('getBundleNameByUid failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s' + err.message); } else { - console.info('getBundleNameByUid successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getBundleNameByUid failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s' + err.message); } ``` @@ -1335,7 +1361,7 @@ try { getBundleNameByUid(uid: number): Promise\; -以异步方法根据给定的uid获取bundleName,使用Promise形式返回结果。 +以异步方法根据给定的uid获取对应的bundleName,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1366,16 +1392,17 @@ getBundleNameByUid(uid: number): Promise\; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let uid = 20010005; try { bundleManager.getBundleNameByUid(uid).then((data) => { - console.info('getBundleNameByUid successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getBundleNameByUid failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getBundleNameByUid failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s' + err.message); } ``` @@ -1410,20 +1437,21 @@ getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), ca **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let hapFilePath = "/data/xxx/test.hap"; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; try { bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => { if (err) { - console.error('getBundleArchiveInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message); } else { - console.info('getBundleArchiveInfo successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getBundleArchiveInfo failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1463,18 +1491,19 @@ getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag)): **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let hapFilePath = "/data/xxx/test.hap"; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; try { bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => { - console.info('getBundleArchiveInfo successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getBundleArchiveInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getBundleArchiveInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1482,7 +1511,7 @@ try { cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\): void; -以异步方法根据给定的bundleName清理BundleCache,并获取清理结果,使用callback形式返回结果。 +以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1509,19 +1538,20 @@ cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\): void; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = "com.ohos.myapplication"; try { bundleManager.cleanBundleCacheFiles(bundleName, err => { if (err) { - console.error('cleanBundleCacheFiles failed:' + err.message); + hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message); } else { - console.info('cleanBundleCacheFiles successfully.'); + hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); } }); } catch (err) { - console.error('cleanBundleCacheFiles failed:' + err.message); + hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message); } ``` @@ -1529,7 +1559,7 @@ try { cleanBundleCacheFiles(bundleName: string): Promise\; -以异步方法根据给定的bundleName清理BundleCache,并获取清理结果,使用Promise形式返回结果。 +以异步方法根据给定的bundleName清理BundleCache,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1547,7 +1577,7 @@ cleanBundleCacheFiles(bundleName: string): Promise\; | 类型 | 说明 | | -------------- | ------------------------------------------------------------ | -| Promise\ | Promise对象,返回true表示清理应用缓存目录数据成功,返回false表示清理应用缓存目录数据失败。 | +| Promise\ | 无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。 | **错误码:** @@ -1561,17 +1591,18 @@ cleanBundleCacheFiles(bundleName: string): Promise\; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = "com.ohos.myapplication"; try { - bundleManager.cleanBundleCacheFiles(bundleName).then(()=> { - console.info('cleanBundleCacheFiles successfully.'); - }).catch(err=> { - console.error('cleanBundleCacheFiles failed:' + err.message); + bundleManager.cleanBundleCacheFiles(bundleName).then(() => { + hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); + }).catch(err => { + hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message); }); } catch (err) { - console.error('cleanBundleCacheFiles failed:' + err.message); + hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message); } ``` @@ -1579,7 +1610,7 @@ try { setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\): void; -设置指定应用的禁用使能状态,使用callback形式返回结果。 +设置指定应用的禁用或使能状态,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1593,7 +1624,7 @@ setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCal | ---------- | ------- | ---- | ------------------------------------- | | bundleName | string | 是 | 指定应用的bundleName。 | | isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | -| callback | AsyncCallback\ | 是 | 回调函数,当设置应用禁用使能状态成功时,err为null,否则为错误对象。 | +| callback | AsyncCallback\ | 是 | 回调函数,当设置应用禁用或使能状态成功时,err为null,否则为错误对象。 | **错误码:** @@ -1606,19 +1637,20 @@ setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCal **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = "com.ohos.myapplication"; try { bundleManager.setApplicationEnabled(bundleName, false, err => { if (err) { - console.error('setApplicationEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message); } else { - console.info('setApplicationEnabled successfully.'); + hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.'); } }); } catch (err) { - console.error('setApplicationEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message); } ``` @@ -1626,7 +1658,7 @@ try { setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\; -设置指定应用的禁用使能状态,使用Promise形式返回结果。 +设置指定应用的禁用或使能状态,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1658,17 +1690,18 @@ setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = "com.ohos.myapplication"; try { - bundleManager.setApplicationEnabled(bundleName, false).then(()=> { - console.info('setApplicationEnabled successfully.'); - }).catch(err=> { - console.error('setApplicationEnabled failed:' + err.message); + bundleManager.setApplicationEnabled(bundleName, false).then(() => { + hilog.info(0x0000, "testTag", "setApplicationEnabled successfully."); + }).catch(err => { + hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message); }); } catch (err) { - console.error('setApplicationEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message); } ``` @@ -1676,7 +1709,7 @@ try { setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean, callback: AsyncCallback\): void; -设置指定组件的禁用使能状态,使用callback形式返回结果。 +设置指定组件的禁用或使能状态,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1690,7 +1723,7 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE | -------- | ----------- | ---- | ------------------------------------- | | info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | | isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | -| callback | AsyncCallback\ | 是 | 回调函数,当设置组件禁用使能状态成功时,err为null,否则为错误对象。 | +| callback | AsyncCallback\ | 是 | 回调函数,当设置组件禁用或使能状态成功时,err为null,否则为错误对象。 | **错误码:** @@ -1704,7 +1737,8 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let userId = 100; let want = { @@ -1715,21 +1749,21 @@ let info; try { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { - console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo)); info = abilitiesInfo[0]; bundleManager.setAbilityEnabled(info, false, err => { if (err) { - console.error('setAbilityEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s' + err.message); } else { - console.info('setAbilityEnabled successfully.'); + hilog.info(0x0001, "testTag", "setAbilityEnabled successfully."); } }); }).catch(error => { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1737,7 +1771,7 @@ try { setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): Promise\; -设置指定组件的禁用使能状态,使用Promise形式返回结果。 +设置指定组件的禁用或使能状态,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1770,7 +1804,8 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let userId = 100; let want = { @@ -1781,19 +1816,19 @@ let info; try { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { - console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo)); info = abilitiesInfo[0]; - bundleManager.setAbilityEnabled(info, false).then(()=> { - console.info('setAbilityEnabled successfully.'); - }).catch(err=> { - console.error('setAbilityEnabled failed:' + err.message); + bundleManager.setAbilityEnabled(info, false).then(() => { + hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); + }).catch(err => { + hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s' + err.message); }); }).catch(error => { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1801,7 +1836,7 @@ try { isApplicationEnabled(bundleName: string, callback: AsyncCallback\): void; -以异步的方法获取指定应用的禁用使能状态,使用callback形式返回结果。 +以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1825,19 +1860,20 @@ isApplicationEnabled(bundleName: string, callback: AsyncCallback\): voi **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; try { bundleManager.isApplicationEnabled(bundleName, (err, data) => { if (err) { - console.error('isApplicationEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s' + err.message); } else { - console.info('isApplicationEnabled successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('isApplicationEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s' + err.message); } ``` @@ -1845,7 +1881,7 @@ try { isApplicationEnabled(bundleName: string): Promise\; -以异步的方法获取指定应用的禁用使能状态,使用Promise形式返回结果。 +以异步的方法获取指定应用的禁用或使能状态,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1874,17 +1910,18 @@ isApplicationEnabled(bundleName: string): Promise\; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; try { bundleManager.isApplicationEnabled(bundleName).then((data) => { - console.info('isApplicationEnabled successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('isApplicationEnabled failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('isApplicationEnabled failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s' + err.message); } ``` @@ -1892,7 +1929,7 @@ try { isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), callback: AsyncCallback\): void; -以异步的方法获取指定组件的禁用使能状态,使用callback形式返回结果。 +以异步的方法获取指定组件的禁用或使能状态,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1917,7 +1954,8 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), call **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let userId = 100; let want = { @@ -1928,21 +1966,21 @@ let info; try { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { - console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo)); info = abilitiesInfo[0]; bundleManager.isAbilityEnabled(info, (err, data) => { if (err) { - console.error('isAbilityEnabled failed:' + err.message); + hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s' + err.message); } else { - console.info('isAbilityEnabled successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', + JSON.stringify(data)); } }); }).catch(error => { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); } ``` @@ -1950,7 +1988,7 @@ try { isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Promise\; -以异步的方法获取指定组件的禁用使能状态,使用Promise形式返回结果。 +以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -1980,7 +2018,8 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Pro **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let userId = 100; let want = { @@ -1991,19 +2030,19 @@ let info; try { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { - console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo)); + hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo)); info = abilitiesInfo[0]; bundleManager.isAbilityEnabled(info).then((data) => { - console.info('isAbilityEnabled successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(err => { - console.error('isAbilityEnabled failed. Cause: ' + err.message); + hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s' + err.message); }); }).catch(error => { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('queryAbilityInfo failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message); } ``` @@ -2011,7 +2050,7 @@ try { getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\): void; -以异步方法根据给定的bundleName和userId获取用于启动应用程序主要功能,使用callback形式返回结果。 +以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -2040,20 +2079,21 @@ getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallba **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let userId = 100; try { bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => { if (err) { - console.error('getLaunchWantForBundle failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message); } else { - console.info('getLaunchWantForBundle successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getLaunchWantForBundle failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message); } ``` @@ -2061,7 +2101,7 @@ try { getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\): void; -以异步方法根据给定的bundleName获取用于启动应用程序主要功能,使用callback形式返回结果。 +以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -2089,19 +2129,20 @@ getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\): void **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; try { bundleManager.getLaunchWantForBundle(bundleName, (err, data) => { if (err) { - console.error('getLaunchWantForBundle failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message); } else { - console.info('getLaunchWantForBundle successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getLaunchWantForBundle failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message); } ``` @@ -2109,7 +2150,7 @@ try { getLaunchWantForBundle(bundleName: string, userId?: number): Promise\; -以异步方法根据给定的bundleName和userId获取用于启动应用程序主要功能,使用Promise形式返回结果。 +以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -2143,18 +2184,19 @@ getLaunchWantForBundle(bundleName: string, userId?: number): Promise\; **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let userId = 100; try { bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => { - console.info('getLaunchWantForBundle successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getLaunchWantForBundle failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getLaunchWantForBundle failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s' + err.message); } ``` @@ -2190,7 +2232,8 @@ getProfileByAbility(moduleName: string, abilityName: string, metadataName: strin **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let moduleName = 'entry'; let abilityName = 'MainAbility'; let metadataName = 'com.example.myapplication.metadata'; @@ -2198,13 +2241,13 @@ let metadataName = 'com.example.myapplication.metadata'; try { bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => { if (err) { - console.error('getProfileByAbility failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message); } else { - console.info('getProfileByAbility successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getProfileByAbility failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message); } ``` @@ -2245,34 +2288,36 @@ getProfileByAbility(moduleName: string, abilityName: string, metadataName?: stri **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let moduleName = 'entry'; let abilityName = 'MainAbility'; try { bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => { - console.info('getProfileByAbility successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getProfileByAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getProfileByAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message); } ``` ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let moduleName = 'entry'; let abilityName = 'MainAbility'; let metadataName = 'com.example.myapplication.metadata'; try { bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => { - console.info('getProfileByAbility successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getProfileByAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getProfileByAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message); } ``` @@ -2307,7 +2352,8 @@ getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, m **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let moduleName = 'entry'; let extensionAbilityName = 'com.example.myapplication.extension'; let metadataName = 'com.example.myapplication.metadata'; @@ -2315,13 +2361,13 @@ let metadataName = 'com.example.myapplication.metadata'; try { bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => { if (err) { - console.error('getProfileByExtensionAbility failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s' + err.message); } else { - console.info('getProfileByExtensionAbility successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getProfileByExtensionAbility failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s' + err.message); } ``` @@ -2361,29 +2407,30 @@ getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, m **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let moduleName = 'entry'; let extensionAbilityName = 'com.example.myapplication.extension'; let metadataName = 'com.example.myapplication.metadata'; try { bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => { - console.info('getProfileByExtensionAbility successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getProfileByExtensionAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getProfileByExtensionAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s' + err.message); } try { bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => { - console.info('getProfileByExtensionAbility successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getProfileByExtensionAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getProfileByExtensionAbility failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s' + err.message); } ``` @@ -2391,7 +2438,7 @@ try { getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void; -以异步方法根据给定的permissionName获取PermissionDef,使用callback形式返回结果。 +以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -2417,18 +2464,19 @@ getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let permission = "ohos.permission.GET_BUNDLE_INFO"; try { bundleManager.getPermissionDef(permission, (err, data) => { if (err) { - console.error('getPermissionDef failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s' + err.message); } else { - console.info('getPermissionDef successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getPermissionDef failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s' + err.message); } ``` @@ -2436,7 +2484,7 @@ try { getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>; -以异步方法根据给定的permissionName获取PermissionDef,使用Promise形式返回结果。 +以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise形式返回结果。 **系统接口:** 此接口为系统接口。 @@ -2467,16 +2515,17 @@ getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundl **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let permissionName = "ohos.permission.GET_BUNDLE_INFO"; try { bundleManager.getPermissionDef(permissionName).then((data) => { - console.info('getPermissionDef successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getPermissionDef failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getPermissionDef failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s' + err.message); } ``` @@ -2516,7 +2565,8 @@ getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, cal **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let moduleName = 'entry'; let abilityName = 'MainAbility'; @@ -2524,13 +2574,13 @@ let abilityName = 'MainAbility'; try { bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => { if (err) { - console.error('getAbilityLabel failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s' + err.message); } else { - console.info('getAbilityLabel successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getAbilityLabel failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s' + err.message); } ``` @@ -2575,19 +2625,20 @@ getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Pr **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let moduleName = 'entry'; let abilityName = 'MainAbility'; try { bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => { - console.info('getAbilityLabel successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getAbilityLabel failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getAbilityLabel failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s' + err.message); } ``` @@ -2627,7 +2678,8 @@ getAbilityIcon(bundleName: string, moduleName: string, abilityName: string, call **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let moduleName = 'entry'; let abilityName = 'MainAbility'; @@ -2635,13 +2687,13 @@ let abilityName = 'MainAbility'; try { bundleManager.getAbilityIcon(bundleName, moduleName, abilityName, (err, data) => { if (err) { - console.error('getAbilityIcon failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAbilityIcon failed: %{public}s' + err.message); } else { - console.info('getAbilityIcon successfully:' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAbilityIcon successfully: %{public}s', + JSON.stringify(data)); } }); } catch (err) { - console.error('getAbilityIcon failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getAbilityIcon failed: %{public}s' + err.message); } ``` @@ -2686,19 +2738,20 @@ getAbilityIcon(bundleName: string, moduleName: string, abilityName: string): Pro **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let moduleName = 'entry'; let abilityName = 'MainAbility'; try { bundleManager.getAbilityIcon(bundleName, moduleName, abilityName).then((data) => { - console.info('getAbilityIcon successfully. Data: ' + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getAbilityIcon successfully. Data: %{public}s', + JSON.stringify(data)); }).catch(error => { - console.error('getAbilityIcon failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAbilityIcon failed. Cause: %{public}s' + err.message); }); } catch (error) { - console.error('getAbilityIcon failed. Cause: ' + error.message); + hilog.error(0x0000, 'testTag', 'getAbilityIcon failed. Cause: %{public}s' + err.message); } ``` @@ -2706,13 +2759,13 @@ try { getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md); -以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo +以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO -**系统能力:** SystemCapability.BundleManager.BundleFramework.Core +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core。 **参数:** @@ -2720,7 +2773,7 @@ getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: num | ----------- | ------ | ---- | ----------------------------------------------------------| | bundleName | string | 是 | 表示应用程序的bundleName。 | | applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | -| userId | number | 是 | 表示用户ID。 | +| userId | number | 否 | 表示用户ID。 | **返回值:** @@ -2741,65 +2794,31 @@ getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: num **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; let userId = 100; try { let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId); - console.info("getApplicationInfoSync successfully:" + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', + JSON.stringify(data)); } catch (err) { - console.error('getApplicationInfoSync failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s' + err.message); } ``` -### bundleManager.getApplicationInfoSync - -getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md); - -以同步方法根据给定的bundleName和applicationFlags获取ApplicationInfo - -**系统接口:** 此接口为系统接口。 - -**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO - -**系统能力:** SystemCapability.BundleManager.BundleFramework.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ----------------------------------------------------------| -| bundleName | string | 是 | 表示应用程序的bundleName。 | -| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | - -**返回值:** - -| 类型 | 说明 | -| --------------- | ------------------------- | -| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | - -**错误码:** - -以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 - -| 错误码ID | 错误信息 | -| -------- | -------------------------------------- | -| 17700001 | The specified bundleName is not found. | -| 17700026 | The specified bundle is disabled. | - -**示例:** - ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; try { let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags); - console.info("getApplicationInfoSync successfully:" + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', + JSON.stringify(data)); } catch (err) { - console.error('getApplicationInfoSync failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s' + err.message); } ``` @@ -2821,7 +2840,7 @@ getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId | ----------- | ------ | ---- | -------------------------------------------------------- | | bundleName | string | 是 | 表示应用程序的bundleName。 | | bundleFlags | [number](#bundleflag) | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | -| userId | number | 是 | 表示用户ID。 | +| userId | number | 否 | 表示用户ID。 | **返回值:** @@ -2842,64 +2861,29 @@ getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId **示例:** ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; let userId = 100; try { let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId); - console.info("getBundleInfoSync successfully :" + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', + JSON.stringify(data)); } catch (err) { - console.error('getBundleInfoSync failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s' + err.message); } ``` -### bundleManager.getBundleInfoSync - -getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md); - -以同步方法根据给定的bundleName和bundleFlags获取BundleInfo。 - -**系统接口:** 此接口为系统接口。 - -**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO - -**系统能力:** SystemCapability.BundleManager.BundleFramework.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | -------------------------------------------------------- | -| bundleName | string | 是 | 表示应用程序的bundleName。 | -| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | - -**返回值:** - -| 类型 | 说明 | -| ---------- | -------------------- | -| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | - -**错误码:** - -以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 - -| 错误码ID | 错误信息 | -| -------- | ------------------------------------- | -| 17700001 | The specified bundleName is not found. | -| 17700004 | The specified user ID is not found. | -| 17700026 | The specified bundle is disabled. | - -**示例:** - ```ts -import bundleManager from '@ohos.bundle.bundleManager' +import bundleManager from '@ohos.bundle.bundleManager'; +import hilog from '@ohos.hilog'; let bundleName = 'com.example.myapplication'; let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; try { let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags); - console.info("getBundleInfoSync successfully :" + JSON.stringify(data)); + hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', + JSON.stringify(data)); } catch (err) { - console.error('getBundleInfoSync failed:' + err.message); + hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s' + err.message); } ``` -- GitLab