1# @ohos.bundle.bundleManager (bundleManager模块) 2 3本模块提供应用信息查询能力,支持BundleInfo、ApplicationInfo、Ability、ExtensionAbility等信息的查询 4 5> **说明:** 6> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7 8## 导入模块 9 10```ts 11import bundleManager from '@ohos.bundle.bundleManager'; 12``` 13 14## 权限列表 15 16| 权限 | 权限等级 | 描述 | 17| ------------------------------------------ | ------------ | ------------------| 18| ohos.permission.GET_BUNDLE_INFO | normal | 允许查询应用的基本信息。 | 19| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 允许查询应用的基本信息和其他敏感信息。 | 20| ohos.permission.REMOVE_CACHE_FILES | system_basic | 清理应用缓存。 | 21|ohos.permission.CHANGE_ABILITY_ENABLED_STATE| system_basic | 设置禁用使能所需的权限。 | 22| ohos.permission.GET_INSTALLED_BUNDLE_LIST | system_basic | 读取已安装应用列表。 | 23 24权限等级参考[权限等级说明](../../security/accesstoken-overview.md#权限等级说明)。 25 26## 枚举 27 28### BundleFlag 29 30包信息标志,指示需要获取的包信息的内容。 31 32 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 33 34| 名称 | 值 | 说明 | 35| ----------------------------------------- | ---------- | ------------------------------------------------------------ | 36| GET_BUNDLE_INFO_DEFAULT | 0x00000000 | 用于获取默认bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 37| GET_BUNDLE_INFO_WITH_APPLICATION | 0x00000001 | 用于获取包含applicationInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 38| GET_BUNDLE_INFO_WITH_HAP_MODULE | 0x00000002 | 用于获取包含hapModuleInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability、extensionAbility和permission的信息。 | 39| GET_BUNDLE_INFO_WITH_ABILITY | 0x00000004 | 用于获取包含ability的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、extensionAbility和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 40| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY | 0x00000008 | 用于获取包含extensionAbility的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability 和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 41| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION | 0x00000010 | 用于获取包含permission的bundleInfo。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、extensionAbility和ability的信息。 | 42| GET_BUNDLE_INFO_WITH_METADATA | 0x00000020 | 用于获取applicationInfo、moduleInfo和abilityInfo中包含的metadata。它不能单独使用,它需要与GET_BUNDLE_INFO_WITH_APPLICATION、GET_BUNDLE_INFO_WITH_HAP_MODULE、GET_BUNDLE_INFO_WITH_ABILITY、GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY一起使用。 | 43| GET_BUNDLE_INFO_WITH_DISABLE | 0x00000040 | 用于获取application被禁用的BundleInfo和被禁用的Ability信息。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 44| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO | 0x00000080 | 用于获取包含signatureInfo的bundleInfo。获取的bundleInfo不包含applicationInfo、hapModuleInfo、extensionAbility、ability和permission的信息。 | 45 46### ApplicationFlag 47 48应用信息标志,指示需要获取的应用信息的内容。 49 50 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 51 52 **系统接口:** 此接口为系统接口。 53 54| 名称 | 值 | 说明 | 55| ------------------------------------ | ---------- | ------------------------------------------------------------ | 56| GET_APPLICATION_INFO_DEFAULT | 0x00000000 | 用于获取默认的applicationInfo,获取的applicationInfo不包含permission和metadata信息。 | 57| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的applicationInfo。 | 58| GET_APPLICATION_INFO_WITH_METADATA | 0x00000002 | 用于获取包含metadata的applicationInfo。 | 59| GET_APPLICATION_INFO_WITH_DISABLE | 0x00000004 | 用于获取包含禁用应用程序的applicationInfo。 | 60 61### AbilityFlag 62 63Ability组件信息标志,指示需要获取的Ability组件信息的内容。 64 65 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 66 67 **系统接口:** 此接口为系统接口。 68 69| 名称 | 值 | 说明 | 70| --------------------------------- | ---------- | ------------------------------------------------------------ | 71| GET_ABILITY_INFO_DEFAULT | 0x00000000 | 用于获取默认abilityInfo,获取的abilityInfo不包含permission、metadata和禁用的abilityInfo。 | 72| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的abilityInfo。 | 73| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的abilityInfo。 | 74| GET_ABILITY_INFO_WITH_METADATA | 0x00000004 | 用于获取包含metadata的abilityInfo。 | 75| GET_ABILITY_INFO_WITH_DISABLE | 0x00000008 | 用于获取包含禁用的abilityInfo的abilityInfo。 | 76| GET_ABILITY_INFO_ONLY_SYSTEM_APP | 0x00000010 | 用于仅为系统应用程序获取abilityInfo。 | 77 78### ExtensionAbilityFlag 79 80扩展组件信息标志,指示需要获取的扩展组件信息的内容。 81 82 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 83 84 **系统接口:** 此接口为系统接口。 85 86| 名称 | 值 | 说明 | 87| ------------------------------------------- | ---------- | ------------------------------------------------------------ | 88| GET_EXTENSION_ABILITY_INFO_DEFAULT | 0x00000000 | 用于获取默认extensionAbilityInfo。获取的extensionAbilityInfo不包含permission、metadata 和禁用的abilityInfo。 | 89| GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的extensionAbilityInfo。 | 90| GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的extensionAbilityInfo。 | 91| GET_EXTENSION_ABILITY_INFO_WITH_METADATA | 0x00000004 | 用于获取包含metadata的extensionAbilityInfo。 | 92 93### ExtensionAbilityType 94 95指示扩展组件的类型。 96 97 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 98 99| 名称 | 值 | 说明 | 100|:----------------:|:---:|-----| 101| FORM | 0 | [FormExtensionAbility](../../application-models/service-widget-overview.md):卡片扩展能力,提供卡片开发能力。 | 102| WORK_SCHEDULER | 1 | [WorkSchedulerExtensionAbility](../../task-management/work-scheduler.md):延时任务扩展能力,允许应用在系统闲时执行实时性不高的任务。 | 103| INPUT_METHOD | 2 | [InputMethodExtensionAbility](js-apis-inputmethod-extension-ability.md):输入法扩展能力,用于开发输入法应用。 | 104| SERVICE | 3 | [ServiceExtensionAbility](../../application-models/serviceextensionability.md):后台服务扩展能力,提供后台运行并对外提供相应能力。 | 105| ACCESSIBILITY | 4 | [AccessibilityExtensionAbility](js-apis-application-accessibilityExtensionAbility.md):无障碍服务扩展能力,支持访问与操作前台界面。 | 106| DATA_SHARE | 5 | [DataShareExtensionAbility](../../database/share-data-by-datashareextensionability.md):数据共享扩展能力,用于对外提供数据读写服务。 | 107| FILE_SHARE | 6 | FileShareExtensionAbility:文件共享扩展能力,用于应用间的文件分享。预留能力,当前暂未支持。 | 108| STATIC_SUBSCRIBER| 7 | [StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md):静态广播扩展能力,用于处理静态事件,比如开机事件。 | 109| WALLPAPER | 8 | WallpaperExtensionAbility:壁纸扩展能力,用于实现桌面壁纸。预留能力,当前暂未支持。 | 110| BACKUP | 9 | BackupExtensionAbility:数据备份扩展能力,提供应用数据和公共数据备份回复能力。预留能力,当前暂未支持。 | 111| WINDOW | 10 | [WindowExtensionAbility](js-apis-application-windowExtensionAbility.md):界面组合扩展能力,允许系统应用进行跨应用的界面拉起和嵌入。 | 112| ENTERPRISE_ADMIN | 11 | [EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md):企业设备管理扩展能力,提供企业管理时处理管理事件的能力,比如设备上应用安装事件、锁屏密码输入错误次数过多事件等。 | 113| THUMBNAIL | 13 | ThumbnailExtensionAbility:文件缩略图扩展能力,用于为文件提供图标缩略图的能力。预留能力,当前暂未支持。 | 114| PREVIEW | 14 | PreviewExtensionAbility:文件预览扩展能力,提供文件预览的能力,其他应用可以直接在应用中嵌入显示。预留能力,当前暂未支持。 | 115| PRINT<sup>10+</sup> | 15 | PrintExtensionAbility:文件打印扩展能力,提供应用打印照片、文档等办公场景。当前支持图片打印,文档类型暂未支持。 | 116| SHARE<sup>10+</sup> | 16 | [ShareExtensionAbility](js-apis-app-ability-shareExtensionAbility.md):提供分享业务能力,为开发者提供基于UIExtension的分享业务模板。 | 117| PUSH<sup>10+</sup> | 17 | PushExtensionAbility:推送扩展能力,提供推送场景化消息能力。预留能力,当前暂未支持。 | 118| DRIVER<sup>10+</sup> | 18 | DriverExtensionAbility:驱动扩展能力,提供外设驱动扩展能力,当前暂未支持。 | 119| ACTION<sup>10+</sup> | 19 | [ActionExtensionAbility](js-apis-app-ability-actionExtensionAbility.md):自定义服务扩展能力,为开发者提供基于UIExtension的自定义操作业务模板。 | 120| UNSPECIFIED | 255 | 不指定类型,配合queryExtensionAbilityInfo接口可以查询所有类型的ExtensionAbility。 | 121 122 123### PermissionGrantState 124 125指示权限授予状态。 126 127 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 128 129| 名称 | 值 | 说明 | 130|:----------------:|:---:|:---:| 131| PERMISSION_DENIED| -1 | 拒绝授予权限。 | 132| PERMISSION_GRANTED | 0 | 授予权限。 | 133 134### SupportWindowMode 135 136标识该组件所支持的窗口模式。 137 138 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 139 140| 名称 | 值 | 说明 | 141|:----------------:|:---:|:---:| 142| FULL_SCREEN | 0 | 窗口支持全屏显示。 | 143| SPLIT | 1 | 窗口支持分屏显示。 | 144| FLOATING | 2 | 支持窗口化显示。 | 145 146### LaunchType 147 148指示组件的启动方式。 149 150 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 151 152| 名称 | 值 | 说明 | 153|:----------------:|:---:|:---:| 154| SINGLETON | 0 | ability的启动模式,表示单实例。 | 155| MULTITON | 1 | ability的启动模式,表示普通多实例。 | 156| SPECIFIED | 2 | ability的启动模式,表示该ability内部根据业务自己置顶多实例。 | 157 158### AbilityType 159 160指示Ability组件的类型。 161 162 **模型约束:** 仅可在FA模型下使用 163 164 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 165 166| 名称 | 值 | 说明 | 167| :-----: | ---- | :--------------------------------------------------------: | 168| PAGE | 1 | 表示基于Page模板开发的FA,用于提供与用户交互的能力。 | 169| SERVICE | 2 | 表示基于Service模板开发的PA,用于提供后台运行任务的能力。 | 170| DATA | 3 | 表示基于Data模板开发的PA,用于对外部提供统一的数据访问对象。 | 171 172### DisplayOrientation 173 174标识该Ability的显示模式。该标签仅适用于page类型的Ability。 175 176 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。 177 178| 名称 |值 |说明 | 179|:----------------------------------|---|---| 180| UNSPECIFIED |0 |表示未定义方向模式,由系统判定。 | 181| LANDSCAPE |1 |表示横屏显示模式。 | 182| PORTRAIT |2 |表示竖屏显示模式。 | 183| FOLLOW_RECENT |3 |表示跟随上一个显示模式。 | 184| LANDSCAPE_INVERTED |4 |表示反向横屏显示模式。 | 185| PORTRAIT_INVERTED |5 |表示反向竖屏显示模式。 | 186| AUTO_ROTATION |6 |表示传感器自动旋转模式。 | 187| AUTO_ROTATION_LANDSCAPE |7 |表示传感器自动横向旋转模式。 | 188| AUTO_ROTATION_PORTRAIT |8 |表示传感器自动竖向旋转模式。 | 189| AUTO_ROTATION_RESTRICTED |9 |表示受开关控制的自动旋转模式。 | 190| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|表述受开关控制的自动横向旋转模式。| 191| AUTO_ROTATION_PORTRAIT_RESTRICTED |11|表示受开关控制的自动竖向旋转模式。| 192| LOCKED |12|表示锁定模式。| 193 194### CompatiblePolicy<sup>10+</sup> 195 196标识共享库的版本兼容类型。 197 198 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core 199 200| 名称 | 值 | 说明 | 201| ---------------------- | ---- | -------------------------------- | 202| BACKWARD_COMPATIBILITY | 1 | 该字段表明共享库是向后兼容类型。 | 203 204### ModuleType 205 206标识模块类型。 207 208 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core 209 210| 名称 | 值 | 说明 | 211| ------- | ---- | -------------------- | 212| ENTRY | 1 | 应用的主模块。 | 213| FEATURE | 2 | 应用的动态特性模块。 | 214| SHARED | 3 | 应用的动态共享库模块。 | 215 216### BundleType 217 218标识应用的类型。 219 220 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core 221 222| 名称 | 值 | 说明 | 223| -------------- | ---- | --------------- | 224| APP | 0 | 该Bundle是普通应用程序。 | 225| ATOMIC_SERVICE | 1 | 该Bundle是原子化服务。 | 226 227## 接口 228 229### bundleManager.getBundleInfoForSelf 230 231getBundleInfoForSelf(bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>; 232 233以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用Promise形式返回结果。 234 235**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 236 237**参数:** 238 239| 参数名 | 类型 | 必填 | 说明 | 240| ----------- | ------ | ---- | --------------------- | 241| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 242 243**返回值:** 244 245| 类型 | 说明 | 246| ----------------------------------------------------------- | ------------------------------------- | 247| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回当前应用的BundleInfo。| 248 249**示例:** 250 251```ts 252import bundleManager from '@ohos.bundle.bundleManager'; 253import { BusinessError } from '@ohos.base'; 254import hilog from '@ohos.hilog'; 255let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 256try { 257 bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { 258 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); 259 }).catch((err: BusinessError) => { 260 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message); 261 }); 262} catch (err) { 263 let message = (err as BusinessError).message; 264 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message); 265} 266``` 267 268### bundleManager.getBundleInfoForSelf 269 270getBundleInfoForSelf(bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void; 271 272以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用callback形式返回结果。 273 274**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 275 276**参数:** 277 278| 参数名 | 类型 | 必填 | 说明 | 279| ----------- | ------ | ---- | --------------------- | 280| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 281| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的当前应用的BundleInfo;否则为错误对象。 | 282 283**示例:** 284 285```ts 286import bundleManager from '@ohos.bundle.bundleManager'; 287import { BusinessError } from '@ohos.base'; 288import hilog from '@ohos.hilog'; 289let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 290 291try { 292 bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => { 293 if (err) { 294 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message); 295 } else { 296 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data)); 297 } 298 }); 299} catch (err) { 300 let message = (err as BusinessError).message; 301 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message); 302} 303``` 304 305### bundleManager.getBundleInfo 306 307getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void; 308 309以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用callback形式返回结果。 310 311获取调用方自己的信息时不需要权限。 312 313**系统接口:** 此接口为系统接口。 314 315**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 316 317**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 318 319**参数:** 320 321| 参数名 | 类型 | 必填 | 说明 | 322| ----------- | ------ | ---- | ---------------------------- | 323| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 324| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。| 325| userId | number | 是 | 表示用户ID。 | 326| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的bundleInfo;否则为错误对象。 | 327 328**错误码:** 329 330以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 331 332| 错误码ID | 错误信息 | 333| -------- | ------------------------------------- | 334| 17700001 | The specified bundleName is not found. | 335| 17700004 | The specified user ID is not found. | 336| 17700026 | The specified bundle is disabled. | 337 338**示例:** 339 340```ts 341// 额外获取AbilityInfo 342import bundleManager from '@ohos.bundle.bundleManager'; 343import { BusinessError } from '@ohos.base'; 344import hilog from '@ohos.hilog'; 345let bundleName = 'com.example.myapplication'; 346let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY; 347let userId = 100; 348 349try { 350 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 351 if (err) { 352 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 353 } else { 354 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 355 } 356 }); 357} catch (err) { 358 let message = (err as BusinessError).message; 359 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 360} 361``` 362 363```ts 364// 额外获取ApplicationInfo中的metadata 365import bundleManager from '@ohos.bundle.bundleManager'; 366import { BusinessError } from '@ohos.base'; 367import hilog from '@ohos.hilog'; 368let bundleName = 'com.example.myapplication'; 369let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; 370let userId = 100; 371 372try { 373 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 374 if (err) { 375 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 376 } else { 377 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 378 } 379 }); 380} catch (err) { 381 let message = (err as BusinessError).message; 382 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 383} 384``` 385 386### bundleManager.getBundleInfo 387 388getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void; 389 390以异步方法根据给定的bundleName和bundleFlags获取BundleInfo,使用callback形式返回结果。 391 392获取调用方自己的信息时不需要权限。 393 394**系统接口:** 此接口为系统接口。 395 396**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 397 398**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 399 400**参数:** 401 402| 参数名 | 类型 | 必填 | 说明 | 403| ----------- | ------ | ---- | ---------------------------- | 404| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 405| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。| 406| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | 407 408**错误码:** 409 410以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 411 412| 错误码ID | 错误信息 | 413| -------- | ------------------------------------- | 414| 17700001 | The specified bundleName is not found. | 415| 17700026 | The specified bundle is disabled. | 416 417**示例:** 418 419```ts 420// 额外获取extensionAbility 421import bundleManager from '@ohos.bundle.bundleManager'; 422import { BusinessError } from '@ohos.base'; 423import hilog from '@ohos.hilog'; 424let bundleName = 'com.example.myapplication'; 425let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; 426 427try { 428 bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => { 429 if (err) { 430 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 431 } else { 432 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 433 } 434 }); 435} catch (err) { 436 let message = (err as BusinessError).message; 437 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 438} 439``` 440 441### bundleManager.getBundleInfo 442 443getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: number): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>; 444 445以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用Promise形式返回结果。 446 447获取调用方自己的信息时不需要权限。 448 449**系统接口:** 此接口为系统接口。 450 451**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 452 453**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 454 455**参数:** 456 457| 参数名 | 类型 | 必填 | 说明 | 458| ----------- | ------ | ---- | ---------------------------- | 459| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 460| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 461| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 462 463**返回值:** 464 465| 类型 | 说明 | 466| ----------------------------------------------------------- | --------------------------- | 467| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 | 468 469**错误码:** 470 471以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 472 473| 错误码ID | 错误信息 | 474| -------- | --------------------------------------| 475| 17700001 | The specified bundleName is not found. | 476| 17700004 | The specified user ID is not found. | 477| 17700026 | The specified bundle is disabled. | 478 479**示例:** 480 481```ts 482// 额外获取ApplicationInfo和SignatureInfo 483import bundleManager from '@ohos.bundle.bundleManager'; 484import { BusinessError } from '@ohos.base'; 485import hilog from '@ohos.hilog'; 486let bundleName = 'com.example.myapplication'; 487let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; 488let userId = 100; 489 490try { 491 bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => { 492 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 493 }).catch((err: BusinessError) => { 494 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 495 }); 496} catch (err) { 497 let message = (err as BusinessError).message; 498 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message); 499} 500``` 501 502```ts 503import bundleManager from '@ohos.bundle.bundleManager'; 504import { BusinessError } from '@ohos.base'; 505import hilog from '@ohos.hilog'; 506let bundleName = 'com.example.myapplication'; 507let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 508 509try { 510 bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => { 511 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 512 }).catch((err: BusinessError) => { 513 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 514 }); 515} catch (err) { 516 let message = (err as BusinessError).message; 517 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message); 518} 519 520``` 521 522### bundleManager.getApplicationInfo 523 524getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void; 525 526以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用callback形式返回结果。 527 528获取调用方自己的信息时不需要权限。 529 530**系统接口:** 此接口为系统接口。 531 532**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 533 534**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 535 536**参数:** 537 538| 参数名 | 类型 | 必填 | 说明 | 539| ---------- | ------ | ---- | ---------------------------- | 540| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 541| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 542| userId | number | 是 | 表示用户ID。 | 543| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | 544 545**错误码:** 546 547以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 548 549| 错误码ID | 错误信息 | 550| -------- | --------------------------------------| 551| 17700001 | The specified bundleName is not found. | 552| 17700004 | The specified user ID is not found. | 553| 17700026 | The specified bundle is disabled. | 554 555**示例:** 556 557```ts 558import bundleManager from '@ohos.bundle.bundleManager'; 559import { BusinessError } from '@ohos.base'; 560import hilog from '@ohos.hilog'; 561let bundleName = 'com.example.myapplication'; 562let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 563let userId = 100; 564 565try { 566 bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => { 567 if (err) { 568 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 569 } else { 570 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 571 } 572 }); 573} catch (err) { 574 let message = (err as BusinessError).message; 575 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message); 576} 577``` 578 579### bundleManager.getApplicationInfo 580 581getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void; 582 583以异步方法根据给定的bundleName和appFlags获取ApplicationInfo,使用callback形式返回结果。 584 585获取调用方自己的信息时不需要权限。 586 587**系统接口:** 此接口为系统接口。 588 589**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 590 591**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 592 593**参数:** 594 595| 参数名 | 类型 | 必填 | 说明 | 596| ---------- | ------ | ---- | ---------------------------- | 597| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 598| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 599| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | 600 601**错误码:** 602 603以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 604 605| 错误码ID | 错误信息 | 606| -------- | --------------------------------------| 607| 17700001 | The specified bundleName is not found. | 608| 17700026 | The specified bundle is disabled. | 609 610**示例:** 611 612```ts 613import bundleManager from '@ohos.bundle.bundleManager'; 614import { BusinessError } from '@ohos.base'; 615import hilog from '@ohos.hilog'; 616let bundleName = 'com.example.myapplication'; 617let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 618 619try { 620 bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => { 621 if (err) { 622 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 623 } else { 624 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 625 } 626 }); 627} catch (err) { 628 let message = (err as BusinessError).message; 629 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message); 630} 631``` 632 633### bundleManager.getApplicationInfo 634 635getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId?: number): Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>; 636 637以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用Promise形式返回结果。 638 639获取调用方自己的信息时不需要权限。 640 641**系统接口:** 此接口为系统接口。 642 643**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 644 645**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 646 647**参数:** 648 649| 参数名 | 类型 | 必填 | 说明 | 650| ---------- | ------ | ---- | ---------------------------- | 651| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 652| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 653| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 654 655**返回值:** 656 657| 类型 | 说明 | 658| ------------------------------------------------------------ | -------------------------------- | 659| Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Promise对象,返回ApplicationInfo。 | 660 661**错误码:** 662 663以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 664 665| 错误码ID | 错误信息 | 666| -------- | ------------------------------------- | 667| 17700001 | The specified bundleName is not found. | 668| 17700004 | The specified user ID is not found. | 669| 17700026 | The specified bundle is disabled. | 670 671**示例:** 672 673```ts 674import bundleManager from '@ohos.bundle.bundleManager'; 675import { BusinessError } from '@ohos.base'; 676import hilog from '@ohos.hilog'; 677let bundleName = 'com.example.myapplication'; 678let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 679let userId = 100; 680 681try { 682 bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => { 683 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 684 }).catch((err: BusinessError) => { 685 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message); 686 }); 687} catch (err) { 688 let message = (err as BusinessError).message; 689 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', message); 690} 691``` 692 693### bundleManager.getAllBundleInfo 694 695getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void; 696 697以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。 698 699**系统接口:** 此接口为系统接口。 700 701**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 702 703**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 704 705**参数:** 706 707| 参数名 | 类型 | 必填 | 说明 | 708| ----------- | ------ | ---- | -------------------------------------------------- | 709| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 710| userId | number | 是 | 表示用户ID。 | 711| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 | 712 713**错误码:** 714 715以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 716 717| 错误码ID | 错误信息 | 718| -------- | --------------------------------- | 719| 17700004 | The specified user ID is not found. | 720 721**示例:** 722 723```ts 724import bundleManager from '@ohos.bundle.bundleManager'; 725import { BusinessError } from '@ohos.base'; 726import hilog from '@ohos.hilog'; 727let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 728let userId = 100; 729 730try { 731 bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => { 732 if (err) { 733 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 734 } else { 735 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 736 } 737 }); 738} catch (err) { 739 let message = (err as BusinessError).message; 740 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message); 741} 742``` 743 744### bundleManager.getAllBundleInfo 745 746getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void; 747 748以异步方法根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback形式返回结果。 749 750**系统接口:** 此接口为系统接口。 751 752**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 753 754**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 755 756**参数:** 757 758| 参数名 | 类型 | 必填 | 说明 | 759| ----------- | ------ | ---- | -------------------------------------------------- | 760| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 761| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 | 762 763**示例:** 764 765```ts 766import bundleManager from '@ohos.bundle.bundleManager'; 767import { BusinessError } from '@ohos.base'; 768import hilog from '@ohos.hilog'; 769let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 770 771try { 772 bundleManager.getAllBundleInfo(bundleFlags, (err, data) => { 773 if (err) { 774 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 775 } else { 776 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 777 } 778 }); 779} catch (err) { 780 let message = (err as BusinessError).message; 781 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message); 782} 783``` 784 785### bundleManager.getAllBundleInfo 786 787getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>; 788 789以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise形式返回结果。 790 791**系统接口:** 此接口为系统接口。 792 793**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 794 795**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 796 797**参数:** 798 799| 参数名 | 类型 | 必填 | 说明 | 800| ----------- | ------ | ---- | -------------------------------------------------- | 801| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 802| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 803 804**返回值:** 805 806| 类型 | 说明 | 807| ------------------------------------------------------------ | ----------------------------------- | 808| Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Promise对象,返回Array\<BundleInfo>。 | 809 810**错误码:** 811 812以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 813 814| 错误码ID | 错误信息 | 815| -------- | ---------------------------------- | 816| 17700004 | The specified user ID is not found. | 817 818**示例:** 819 820```ts 821import bundleManager from '@ohos.bundle.bundleManager'; 822import { BusinessError } from '@ohos.base'; 823import hilog from '@ohos.hilog'; 824let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 825 826try { 827 bundleManager.getAllBundleInfo(bundleFlags).then((data) => { 828 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 829 }).catch((err: BusinessError) => { 830 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message); 831 }); 832} catch (err) { 833 let message = (err as BusinessError).message; 834 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', message); 835} 836``` 837 838### bundleManager.getAllApplicationInfo 839 840getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void; 841 842以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。 843 844**系统接口:** 此接口为系统接口。 845 846**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 847 848**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 849 850**参数:** 851 852| 参数名 | 类型 | 必填 | 说明 | 853| -------- | ------ | ---- | ----------------------------------------------------------- | 854| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 855| userId | number | 是 | 表示用户ID。 | 856| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 | 857 858**错误码:** 859 860以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 861 862| 错误码ID | 错误信息 | 863| -------- | ---------------------------------- | 864| 17700004 | The specified user ID is not found. | 865 866**示例:** 867 868```ts 869import bundleManager from '@ohos.bundle.bundleManager'; 870import { BusinessError } from '@ohos.base'; 871import hilog from '@ohos.hilog'; 872let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 873let userId = 100; 874 875try { 876 bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => { 877 if (err) { 878 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 879 } else { 880 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 881 } 882 }); 883} catch (err) { 884 let message = (err as BusinessError).message; 885 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message); 886} 887``` 888 889### bundleManager.getAllApplicationInfo 890 891getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void; 892 893以异步方法根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback形式返回结果。 894 895**系统接口:** 此接口为系统接口。 896 897**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 898 899**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 900 901**参数:** 902 903| 参数名 | 类型 | 必填 | 说明 | 904| -------- | ------ | ---- | ----------------------------------------------------------- | 905| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 906| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 | 907 908**示例:** 909 910```ts 911import bundleManager from '@ohos.bundle.bundleManager'; 912import { BusinessError } from '@ohos.base'; 913import hilog from '@ohos.hilog'; 914let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 915 916try { 917 bundleManager.getAllApplicationInfo(appFlags, (err, data) => { 918 if (err) { 919 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 920 } else { 921 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 922 } 923 }); 924} catch (err) { 925 let message = (err as BusinessError).message; 926 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message); 927} 928``` 929 930### bundleManager.getAllApplicationInfo 931 932getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>; 933 934以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise形式返回结果。 935 936**系统接口:** 此接口为系统接口。 937 938**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 939 940**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 941 942**参数:** 943 944| 参数名 | 类型 | 必填 | 说明 | 945| -------- | ------ | ---- | ---------------------------------------------------------- | 946| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 947| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 948 949**返回值:** 950 951| 类型 | 说明 | 952| ------------------------------------------------------------ | ---------------------------------------- | 953| Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Promise对象,返回Array\<ApplicationInfo>。 | 954 955**错误码:** 956 957以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 958 959| 错误码ID | 错误信息 | 960| -------- | ---------------------------------- | 961| 17700004 | The specified user ID is not found. | 962 963**示例:** 964 965```ts 966import bundleManager from '@ohos.bundle.bundleManager'; 967import { BusinessError } from '@ohos.base'; 968import hilog from '@ohos.hilog'; 969let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 970 971try { 972 bundleManager.getAllApplicationInfo(appFlags).then((data) => { 973 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 974 }).catch((err: BusinessError) => { 975 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message); 976 }); 977} catch (err) { 978 let message = (err as BusinessError).message; 979 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', message); 980} 981 982``` 983 984### bundleManager.queryAbilityInfo 985 986queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: number, callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void; 987 988以异步方法根据给定的want、abilityFlags和userId获取多个AbilityInfo,使用callback形式返回结果。 989 990**系统接口:** 此接口为系统接口。 991 992**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 993 994**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 995 996**参数:** 997 998| 参数名 | 类型 | 必填 | 说明 | 999| ------------ | ------ | ---- | ------------------------------------------------------- | 1000| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1001| abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | 1002| userId | number | 是 | 表示用户ID。 | 1003| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 | 1004 1005**错误码:** 1006 1007以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1008 1009| 错误码ID | 错误信息 | 1010| -------- | -------------------------------------- | 1011| 17700001 | The specified bundleName is not found. | 1012| 17700003 | The specified ability is not found. | 1013| 17700004 | The specified userId is invalid. | 1014| 17700026 | The specified bundle is disabled. | 1015| 17700029 | The specified ability is disabled. | 1016 1017**示例:** 1018 1019```ts 1020import bundleManager from '@ohos.bundle.bundleManager'; 1021import { BusinessError } from '@ohos.base'; 1022import hilog from '@ohos.hilog'; 1023import Want from '@ohos.app.ability.Want'; 1024let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1025let userId = 100; 1026let want: Want = { 1027 bundleName : "com.example.myapplication", 1028 abilityName : "EntryAbility" 1029}; 1030 1031try { 1032 bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => { 1033 if (err) { 1034 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1035 } else { 1036 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1037 } 1038 }); 1039} catch (err) { 1040 let message = (err as BusinessError).message; 1041 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message); 1042} 1043``` 1044 1045### bundleManager.queryAbilityInfo 1046 1047queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void; 1048 1049以异步方法根据给定的want和abilityFlags获取一个或多个AbilityInfo,使用callback形式返回结果。 1050 1051**系统接口:** 此接口为系统接口。 1052 1053**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1054 1055**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1056 1057**参数:** 1058 1059| 参数名 | 类型 | 必填 | 说明 | 1060| ------------ | ------ | ---- | -------------------------------------------------------| 1061| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1062| abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | 1063| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 | 1064 1065**错误码:** 1066 1067以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1068 1069| 错误码ID | 错误信息 | 1070| -------- | -------------------------------------- | 1071| 17700001 | The specified bundleName is not found. | 1072| 17700003 | The specified ability is not found. | 1073| 17700026 | The specified bundle is disabled. | 1074| 17700029 | The specified ability is disabled. | 1075 1076**示例:** 1077 1078```ts 1079import bundleManager from '@ohos.bundle.bundleManager'; 1080import { BusinessError } from '@ohos.base'; 1081import hilog from '@ohos.hilog'; 1082import Want from '@ohos.app.ability.Want'; 1083let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1084let want: Want = { 1085 bundleName : "com.example.myapplication", 1086 abilityName : "EntryAbility" 1087}; 1088 1089try { 1090 bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => { 1091 if (err) { 1092 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1093 } else { 1094 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1095 } 1096 }); 1097} catch (err) { 1098 let message = (err as BusinessError).message; 1099 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message); 1100} 1101``` 1102 1103### bundleManager.queryAbilityInfo 1104 1105queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>; 1106 1107以异步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo,使用Promise形式返回结果。 1108 1109**系统接口:** 此接口为系统接口。 1110 1111**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1112 1113**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1114 1115**参数:** 1116 1117| 参数名 | 类型 | 必填 | 说明 | 1118| ------------ | ------ | ---- | ------------------------------------------------------- | 1119| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1120| abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | 1121| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1122 1123**返回值:** 1124 1125| 类型 | 说明 | 1126| ------------------------------------------------------------ | ------------------------------------ | 1127| Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Promise对象,返回Array\<AbilityInfo>。 | 1128 1129**错误码:** 1130 1131以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1132 1133| 错误码ID | 错误信息 | 1134| -------- | ------------------------------------- | 1135| 17700001 | The specified bundleName is not found. | 1136| 17700003 | The specified ability is not found. | 1137| 17700004 | The specified userId is invalid. | 1138| 17700026 | The specified bundle is disabled. | 1139| 17700029 | The specified ability is disabled. | 1140 1141**示例:** 1142 1143```ts 1144import bundleManager from '@ohos.bundle.bundleManager'; 1145import { BusinessError } from '@ohos.base'; 1146import hilog from '@ohos.hilog'; 1147import Want from '@ohos.app.ability.Want'; 1148let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1149let userId = 100; 1150let want: Want = { 1151 bundleName : "com.example.myapplication", 1152 abilityName : "EntryAbility" 1153}; 1154 1155try { 1156 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => { 1157 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1158 }).catch((err: BusinessError) => { 1159 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1160 }); 1161} catch (err) { 1162 let message = (err as BusinessError).message; 1163 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1164} 1165``` 1166 1167```ts 1168import bundleManager from '@ohos.bundle.bundleManager'; 1169import { BusinessError } from '@ohos.base'; 1170import hilog from '@ohos.hilog'; 1171import Want from '@ohos.app.ability.Want'; 1172let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1173let want: Want = { 1174 bundleName : "com.example.myapplication", 1175 abilityName : "EntryAbility" 1176}; 1177 1178try { 1179 bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => { 1180 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1181 }).catch((err: BusinessError) => { 1182 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1183 }) 1184} catch (err) { 1185 let message = (err as BusinessError).message; 1186 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1187} 1188``` 1189 1190### bundleManager.queryAbilityInfoSync<sup>10+</sup> 1191 1192queryAbilityInfoSync(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>; 1193 1194以同步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo。 1195 1196**系统接口:** 此接口为系统接口。 1197 1198**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1199 1200**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1201 1202**参数:** 1203 1204| 参数名 | 类型 | 必填 | 说明 | 1205| ------------ | ------ | ---- | ------------------------------------------------------- | 1206| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1207| abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | 1208| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1209 1210**返回值:** 1211 1212| 类型 | 说明 | 1213| ------------------------------------------------------------ | ------------------------------------ | 1214| Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | Array\<AbilityInfo>信息。 | 1215 1216**错误码:** 1217 1218以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1219 1220| 错误码ID | 错误信息 | 1221| -------- | ------------------------------------- | 1222| 17700001 | The specified bundleName is not found. | 1223| 17700003 | The specified ability is not found. | 1224| 17700004 | The specified userId is invalid. | 1225| 17700026 | The specified bundle is disabled. | 1226| 17700029 | The specified ability is disabled. | 1227 1228**示例:** 1229 1230```ts 1231import bundleManager from '@ohos.bundle.bundleManager'; 1232import { BusinessError } from '@ohos.base'; 1233import hilog from '@ohos.hilog'; 1234import Want from '@ohos.app.ability.Want'; 1235let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1236let userId = 100; 1237let want: Want = { 1238 bundleName : "com.example.myapplication", 1239 abilityName : "EntryAbility" 1240}; 1241 1242try { 1243 1244 let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags, userId); 1245 hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos)); 1246} catch (err) { 1247 let message = (err as BusinessError).message; 1248 hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message); 1249} 1250``` 1251 1252```ts 1253import bundleManager from '@ohos.bundle.bundleManager'; 1254import { BusinessError } from '@ohos.base'; 1255import hilog from '@ohos.hilog'; 1256import Want from '@ohos.app.ability.Want'; 1257let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1258let want: Want = { 1259 bundleName : "com.example.myapplication", 1260 abilityName : "EntryAbility" 1261}; 1262 1263try { 1264 let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags); 1265 hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos)); 1266} catch (err) { 1267 let message = (err as BusinessError).message; 1268 hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message); 1269} 1270``` 1271 1272### bundleManager.queryExtensionAbilityInfo 1273 1274queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId: number, callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void; 1275 1276以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。 1277 1278**系统接口:** 此接口为系统接口。 1279 1280**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1281 1282**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1283 1284**参数:** 1285 1286| 参数名 | 类型 | 必填 | 说明 | 1287| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1288| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1289| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1290| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1291| userId | number | 是 | 表示用户ID。 | 1292| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 | 1293 1294**错误码:** 1295 1296以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1297 1298| 错误码ID | 错误信息 | 1299| -------- | ------------------------------------------- | 1300| 17700001 | The specified bundleName is not found. | 1301| 17700003 | The specified extensionAbility is not found. | 1302| 17700004 | The specified userId is invalid. | 1303| 17700026 | The specified bundle is disabled. | 1304 1305**示例:** 1306 1307```ts 1308import bundleManager from '@ohos.bundle.bundleManager'; 1309import { BusinessError } from '@ohos.base'; 1310import hilog from '@ohos.hilog'; 1311import Want from '@ohos.app.ability.Want'; 1312let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1313let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1314let userId = 100; 1315let want: Want = { 1316 bundleName : "com.example.myapplication", 1317 abilityName : "EntryAbility" 1318}; 1319 1320try { 1321 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => { 1322 if (err) { 1323 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1324 } else { 1325 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1326 } 1327 }); 1328} catch (err) { 1329 let message = (err as BusinessError).message; 1330 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message); 1331} 1332``` 1333 1334### bundleManager.queryExtensionAbilityInfo 1335 1336queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void; 1337 1338以异步方法根据给定的want、extensionAbilityType和extensionAbilityFlags获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。 1339 1340**系统接口:** 此接口为系统接口。 1341 1342**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1343 1344**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1345 1346**参数:** 1347 1348| 参数名 | 类型 | 必填 | 说明 | 1349| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1350| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1351| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1352| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1353| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 | 1354 1355**错误码:** 1356 1357以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1358 1359| 错误码ID | 错误信息 | 1360| -------- | -------------------------------------------- | 1361| 17700001 | The specified bundleName is not found. | 1362| 17700003 | The specified extensionAbility is not found. | 1363| 17700026 | The specified bundle is disabled. | 1364 1365**示例:** 1366 1367```ts 1368import bundleManager from '@ohos.bundle.bundleManager'; 1369import { BusinessError } from '@ohos.base'; 1370import hilog from '@ohos.hilog'; 1371import Want from '@ohos.app.ability.Want'; 1372let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1373let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1374let want: Want = { 1375 bundleName : "com.example.myapplication", 1376 abilityName : "EntryAbility" 1377}; 1378 1379try { 1380 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => { 1381 if (err) { 1382 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1383 } else { 1384 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1385 } 1386 }); 1387} catch (err) { 1388 let message = (err as BusinessError).message; 1389 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message); 1390} 1391``` 1392 1393### bundleManager.queryExtensionAbilityInfo 1394 1395queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>; 1396 1397以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo,使用Promise形式返回结果。 1398 1399**系统接口:** 此接口为系统接口。 1400 1401**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1402 1403**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1404 1405**参数:** 1406 1407| 参数名 | 类型 | 必填 | 说明 | 1408| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1409| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1410| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1411| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1412| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1413 1414**返回值:** 1415 1416| 类型 | 说明 | 1417| ------------------------------------------------------------ | --------------------------------------------- | 1418| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Promise对象,返回Array\<ExtensionAbilityInfo>。 | 1419 1420**错误码:** 1421 1422以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1423 1424| 错误码ID | 错误信息 | 1425| -------- | --------------------------------------| 1426| 17700001 | The specified bundleName is not found. | 1427| 17700003 | The specified extensionAbility is not found. | 1428| 17700004 | The specified userId is invalid. | 1429| 17700026 | The specified bundle is disabled. | 1430 1431**示例:** 1432 1433```ts 1434import bundleManager from '@ohos.bundle.bundleManager'; 1435import { BusinessError } from '@ohos.base'; 1436import hilog from '@ohos.hilog'; 1437import Want from '@ohos.app.ability.Want'; 1438 1439let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1440let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1441let userId = 100; 1442let want: Want = { 1443 bundleName : "com.example.myapplication", 1444 abilityName : "EntryAbility" 1445}; 1446 1447try { 1448 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => { 1449 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1450 }).catch((err: BusinessError) => { 1451 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1452 }); 1453} catch (err) { 1454 let message = (err as BusinessError).message; 1455 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message); 1456} 1457``` 1458 1459```ts 1460import bundleManager from '@ohos.bundle.bundleManager'; 1461import { BusinessError } from '@ohos.base'; 1462import hilog from '@ohos.hilog'; 1463import Want from '@ohos.app.ability.Want'; 1464let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1465let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1466let want: Want = { 1467 bundleName : "com.example.myapplication", 1468 abilityName : "EntryAbility" 1469}; 1470 1471try { 1472 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => { 1473 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1474 }).catch((err: BusinessError) => { 1475 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1476 }) 1477} catch (err) { 1478 let message = (err as BusinessError).message; 1479 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message); 1480} 1481``` 1482 1483### bundleManager.queryExtensionAbilityInfoSync<sup>10+</sup> 1484 1485queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>; 1486 1487以同步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo。 1488 1489**系统接口:** 此接口为系统接口。 1490 1491**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1492 1493**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1494 1495**参数:** 1496 1497| 参数名 | 类型 | 必填 | 说明 | 1498| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1499| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1500| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1501| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1502| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1503 1504**返回值:** 1505 1506| 类型 | 说明 | 1507| ------------------------------------------------------------ | --------------------------------------------- | 1508| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | Array\<ExtensionAbilityInfo>信息。 | 1509 1510**错误码:** 1511 1512以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1513 1514| 错误码ID | 错误信息 | 1515| -------- | --------------------------------------| 1516| 17700001 | The specified bundleName is not found. | 1517| 17700003 | The specified extensionAbility is not found. | 1518| 17700004 | The specified userId is invalid. | 1519| 17700026 | The specified bundle is disabled. | 1520 1521**示例:** 1522 1523```ts 1524import bundleManager from '@ohos.bundle.bundleManager'; 1525import { BusinessError } from '@ohos.base'; 1526import hilog from '@ohos.hilog'; 1527import Want from '@ohos.app.ability.Want'; 1528 1529let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1530let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1531let userId = 100; 1532let want: Want = { 1533 bundleName : "com.example.myapplication", 1534 abilityName : "EntryAbility" 1535}; 1536 1537try { 1538 let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId); 1539 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos)); 1540} catch (err) { 1541 let message = (err as BusinessError).message; 1542 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message); 1543} 1544``` 1545 1546```ts 1547import bundleManager from '@ohos.bundle.bundleManager'; 1548import { BusinessError } from '@ohos.base'; 1549import hilog from '@ohos.hilog'; 1550import Want from '@ohos.app.ability.Want'; 1551let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1552let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1553let want: Want = { 1554 bundleName : "com.example.myapplication", 1555 abilityName : "EntryAbility" 1556}; 1557 1558try { 1559 let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags); 1560 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos)); 1561} catch (err) { 1562 let message = (err as BusinessError).message; 1563 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message); 1564} 1565``` 1566 1567### bundleManager.getBundleNameByUid 1568 1569getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void; 1570 1571以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。 1572 1573**系统接口:** 此接口为系统接口。 1574 1575**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1576 1577**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1578 1579**参数:** 1580 1581| 参数名 | 类型 | 必填 | 说明 | 1582| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1583| uid | number | 是 | 表示应用程序的UID。 | 1584| callback | AsyncCallback\<string> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleName;否则为错误对象。 | 1585 1586**错误码:** 1587 1588以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1589 1590| 错误码ID | 错误信息 | 1591| -------- | --------------------- | 1592| 17700021 | The uid is not found. | 1593 1594**示例:** 1595 1596```ts 1597import bundleManager from '@ohos.bundle.bundleManager'; 1598import { BusinessError } from '@ohos.base'; 1599import hilog from '@ohos.hilog'; 1600let uid = 20010005; 1601try { 1602 bundleManager.getBundleNameByUid(uid, (err, data) => { 1603 if (err) { 1604 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message); 1605 } else { 1606 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data)); 1607 } 1608 }); 1609} catch (err) { 1610 let message = (err as BusinessError).message; 1611 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', message); 1612} 1613``` 1614 1615### bundleManager.getBundleNameByUid 1616 1617getBundleNameByUid(uid: number): Promise\<string>; 1618 1619以异步方法根据给定的uid获取对应的bundleName,使用Promise形式返回结果。 1620 1621**系统接口:** 此接口为系统接口。 1622 1623**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1624 1625**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1626 1627**参数:** 1628 1629| 参数名 | 类型 | 必填 | 说明 | 1630| ---- | ------ | ---- | ------------------ | 1631| uid | number | 是 | 表示应用程序的UID。 | 1632 1633**返回值:** 1634 1635| 类型 | 说明 | 1636| ---------------- | --------------------------- | 1637| Promise\<string> | Promise对象,返回bundleName。 | 1638 1639**错误码:** 1640 1641以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1642 1643| 错误码ID | 错误信息 | 1644| -------- | ---------------------| 1645| 17700021 | The uid is not found. | 1646 1647**示例:** 1648 1649```ts 1650import bundleManager from '@ohos.bundle.bundleManager'; 1651import { BusinessError } from '@ohos.base'; 1652import hilog from '@ohos.hilog'; 1653let uid = 20010005; 1654try { 1655 bundleManager.getBundleNameByUid(uid).then((data) => { 1656 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data)); 1657 }).catch((err: BusinessError) => { 1658 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message); 1659 }); 1660} catch (err) { 1661 let message = (err as BusinessError).message; 1662 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', message); 1663} 1664``` 1665 1666### bundleManager.getBundleNameByUidSync<sup>10+</sup> 1667 1668getBundleNameByUidSync(uid: number): string; 1669 1670以同步方法根据给定的uid获取对应的bundleName。 1671 1672**系统接口:** 此接口为系统接口。 1673 1674**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1675 1676**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1677 1678**参数:** 1679 1680| 参数名 | 类型 | 必填 | 说明 | 1681| ---- | ------ | ---- | ------------------ | 1682| uid | number | 是 | 表示应用程序的UID。 | 1683 1684**返回值:** 1685 1686| 类型 | 说明 | 1687| ---------------- | --------------------------- | 1688| string | 返回获取到的bundleName。 | 1689 1690**错误码:** 1691 1692以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1693 1694| 错误码ID | 错误信息 | 1695| -------- | ---------------------| 1696| 17700021 | The uid is not found. | 1697 1698**示例:** 1699 1700```ts 1701import bundleManager from '@ohos.bundle.bundleManager'; 1702import { BusinessError } from '@ohos.base'; 1703import hilog from '@ohos.hilog'; 1704let uid = 20010005; 1705try { 1706 let data = bundleManager.getBundleNameByUidSync(uid); 1707 hilog.info(0x0000, 'testTag', 'getBundleNameByUidSync successfully. Data: %{public}s', JSON.stringify(data)); 1708} catch (err) { 1709 let message = (err as BusinessError).message; 1710 hilog.error(0x0000, 'testTag', 'getBundleNameByUidSync failed. Cause: %{public}s', message); 1711} 1712``` 1713 1714### bundleManager.getBundleArchiveInfo 1715 1716getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void; 1717 1718以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用callback形式返回结果。 1719 1720**系统接口:** 此接口为系统接口。 1721 1722**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1723 1724**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1725 1726**参数:** 1727 1728| 参数名 | 类型 | 必填 | 说明 | 1729| ----------- | ------ | ---- | ----------------------------------------------------------- | 1730| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1731| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1732| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | 1733 1734**错误码:** 1735 1736以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1737 1738| 错误码ID | 错误信息 | 1739| -------- | --------------------------- | 1740| 17700022 | The hapFilePath is invalid. | 1741 1742**示例:** 1743 1744```ts 1745import bundleManager from '@ohos.bundle.bundleManager'; 1746import { BusinessError } from '@ohos.base'; 1747import hilog from '@ohos.hilog'; 1748let hapFilePath = "/data/xxx/test.hap"; 1749let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1750 1751try { 1752 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => { 1753 if (err) { 1754 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1755 } else { 1756 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data)); 1757 } 1758 }); 1759} catch (err) { 1760 let message = (err as BusinessError).message; 1761 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message); 1762} 1763``` 1764 1765### bundleManager.getBundleArchiveInfo 1766 1767getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>; 1768 1769以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用Promise形式返回结果。 1770 1771**系统接口:** 此接口为系统接口。 1772 1773**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1774 1775**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1776 1777**参数:** 1778 1779| 参数名 | 类型 | 必填 | 说明 | 1780| ----------- | ------ | ---- | ------------------------------------------------------------ | 1781| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1782| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1783 1784**返回值:** 1785 1786| 类型 | 说明 | 1787| ----------------------------------------------------------- | --------------------------- | 1788| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 | 1789 1790**错误码:** 1791 1792以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1793 1794| 错误码ID | 错误信息 | 1795| -------- | -------------------------- | 1796| 17700022 | The hapFilePath is invalid. | 1797 1798**示例:** 1799 1800```ts 1801import bundleManager from '@ohos.bundle.bundleManager'; 1802import { BusinessError } from '@ohos.base'; 1803import hilog from '@ohos.hilog'; 1804let hapFilePath = "/data/xxx/test.hap"; 1805let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1806 1807try { 1808 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => { 1809 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data)); 1810 }).catch((err: BusinessError) => { 1811 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1812 }); 1813} catch (err) { 1814 let message = (err as BusinessError).message; 1815 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message); 1816} 1817``` 1818 1819### bundleManager.getBundleArchiveInfoSync<sup>10+</sup> 1820 1821getBundleArchiveInfoSync(hapFilePath: string, bundleFlags: number): BundleInfo; 1822 1823以同步方法根据给定的hapFilePath和bundleFlags获取BundleInfo对象。 1824 1825**系统接口:** 此接口为系统接口。 1826 1827**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1828 1829**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1830 1831**参数:** 1832 1833| 参数名 | 类型 | 必填 | 说明 | 1834| ----------- | ------ | ---- | ------------------------------------------------------------ | 1835| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1836| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1837 1838**返回值:** 1839 1840| 类型 | 说明 | 1841| ----------------------------------------------------------- | --------------------------- | 1842| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 1843 1844**错误码:** 1845 1846以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1847 1848| 错误码ID | 错误信息 | 1849| -------- | -------------------------- | 1850| 17700022 | The hapFilePath is invalid. | 1851 1852**示例:** 1853 1854```ts 1855import bundleManager from '@ohos.bundle.bundleManager'; 1856import { BusinessError } from '@ohos.base'; 1857import hilog from '@ohos.hilog'; 1858let hapFilePath = "/data/xxx/test.hap"; 1859let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1860 1861try { 1862 let data = bundleManager.getBundleArchiveInfoSync(hapFilePath, bundleFlags) 1863 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 1864} catch (err) { 1865 let message = (err as BusinessError).message; 1866 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfoSync failed. Cause: %{public}s', message); 1867} 1868``` 1869 1870### bundleManager.cleanBundleCacheFiles 1871 1872cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\<void>): void; 1873 1874以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。 1875 1876**系统接口:** 此接口为系统接口。 1877 1878**需要权限:** ohos.permission.REMOVE_CACHE_FILES 1879 1880**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1881 1882**参数:** 1883 1884| 参数名 | 类型 | 必填 | 说明 | 1885| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 1886| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 1887| callback | AsyncCallback\<void> | 是 | 回调函数,当清理应用缓存目录数据成功,err为null,否则为错误对象。 | 1888 1889**错误码:** 1890 1891以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1892 1893| 错误码ID | 错误信息 | 1894| -------- | ------------------------------------------------------------ | 1895| 17700001 | The specified bundleName is not found. | 1896| 17700030 | The specified bundle does not support clearing of cache files. | 1897 1898**示例:** 1899 1900```ts 1901import bundleManager from '@ohos.bundle.bundleManager'; 1902import { BusinessError } from '@ohos.base'; 1903import hilog from '@ohos.hilog'; 1904let bundleName = "com.ohos.myapplication"; 1905 1906try { 1907 bundleManager.cleanBundleCacheFiles(bundleName, err => { 1908 if (err) { 1909 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1910 } else { 1911 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1912 } 1913 }); 1914} catch (err) { 1915 let message = (err as BusinessError).message; 1916 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 1917} 1918``` 1919 1920### bundleManager.cleanBundleCacheFiles 1921 1922cleanBundleCacheFiles(bundleName: string): Promise\<void>; 1923 1924以异步方法根据给定的bundleName清理BundleCache,使用Promise形式返回结果。 1925 1926**系统接口:** 此接口为系统接口。 1927 1928**需要权限:** ohos.permission.REMOVE_CACHE_FILES 1929 1930**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1931 1932**参数:** 1933 1934| 参数名 | 类型 | 必填 | 说明 | 1935| ---------- | ------ | ---- | ------------------------------------------ | 1936| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 1937 1938**返回值:** 1939 1940| 类型 | 说明 | 1941| -------------- | ------------------------------------------------------------ | 1942| Promise\<void> | 无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。 | 1943 1944**错误码:** 1945 1946以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1947 1948| 错误码ID | 错误信息 | 1949| -------- | ---------------------------------------------------------- | 1950| 17700001 | The specified bundleName is not found. | 1951| 17700030 | The specified bundle does not support clearing of cache files. | 1952 1953**示例:** 1954 1955```ts 1956import bundleManager from '@ohos.bundle.bundleManager'; 1957import { BusinessError } from '@ohos.base'; 1958import hilog from '@ohos.hilog'; 1959let bundleName = "com.ohos.myapplication"; 1960 1961try { 1962 bundleManager.cleanBundleCacheFiles(bundleName).then(() => { 1963 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1964 }).catch((err: BusinessError) => { 1965 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1966 }); 1967} catch (err) { 1968 let message = (err as BusinessError).message; 1969 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 1970} 1971``` 1972 1973### bundleManager.setApplicationEnabled 1974 1975setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\<void>): void; 1976 1977设置指定应用的禁用或使能状态,使用callback形式返回结果。 1978 1979**系统接口:** 此接口为系统接口。 1980 1981**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 1982 1983**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1984 1985**参数:** 1986 1987| 参数名 | 类型 | 必填 | 说明 | 1988| ---------- | ------- | ---- | ------------------------------------- | 1989| bundleName | string | 是 | 指定应用的bundleName。 | 1990| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 1991| callback | AsyncCallback\<void> | 是 | 回调函数,当设置应用禁用或使能状态成功时,err为null,否则为错误对象。 | 1992 1993**错误码:** 1994 1995以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 1996 1997| 错误码ID | 错误信息 | 1998| -------- | -------------------------------------- | 1999| 17700001 | The specified bundleName is not found. | 2000 2001**示例:** 2002 2003```ts 2004import bundleManager from '@ohos.bundle.bundleManager'; 2005import { BusinessError } from '@ohos.base'; 2006import hilog from '@ohos.hilog'; 2007let bundleName = "com.ohos.myapplication"; 2008 2009try { 2010 bundleManager.setApplicationEnabled(bundleName, false, err => { 2011 if (err) { 2012 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2013 } else { 2014 hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.'); 2015 } 2016 }); 2017} catch (err) { 2018 let message = (err as BusinessError).message; 2019 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2020} 2021``` 2022 2023### bundleManager.setApplicationEnabled 2024 2025setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\<void>; 2026 2027设置指定应用的禁用或使能状态,使用Promise形式返回结果。 2028 2029**系统接口:** 此接口为系统接口。 2030 2031**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2032 2033**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2034 2035**参数:** 2036 2037| 参数名 | 类型 | 必填 | 说明 | 2038| ---------- | ------- | ---- | ------------------------------------- | 2039| bundleName | string | 是 | 表示应用程序的bundleName。 | 2040| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2041 2042**返回值:** 2043 2044| 类型 | 说明 | 2045| -------------- | ------------------------------------ | 2046| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2047 2048**错误码:** 2049 2050以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2051 2052| 错误码ID | 错误信息 | 2053| -------- | -------------------------------------- | 2054| 17700001 | The specified bundleName is not found. | 2055 2056**示例:** 2057 2058```ts 2059import bundleManager from '@ohos.bundle.bundleManager'; 2060import { BusinessError } from '@ohos.base'; 2061import hilog from '@ohos.hilog'; 2062let bundleName = "com.ohos.myapplication"; 2063 2064try { 2065 bundleManager.setApplicationEnabled(bundleName, false).then(() => { 2066 hilog.info(0x0000, "testTag", "setApplicationEnabled successfully."); 2067 }).catch((err: BusinessError) => { 2068 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2069 }); 2070} catch (err) { 2071 let message = (err as BusinessError).message; 2072 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2073} 2074``` 2075 2076### bundleManager.setApplicationEnabledSync<sup>10+</sup> 2077 2078setApplicationEnabledSync(bundleName: string, isEnabled: boolean): void; 2079 2080以同步方法设置指定应用的禁用或使能状态。 2081 2082**系统接口:** 此接口为系统接口。 2083 2084**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2085 2086**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2087 2088**参数:** 2089 2090| 参数名 | 类型 | 必填 | 说明 | 2091| ---------- | ------- | ---- | ------------------------------------- | 2092| bundleName | string | 是 | 指定应用的bundleName。 | 2093| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2094 2095**错误码:** 2096 2097以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2098 2099| 错误码ID | 错误信息 | 2100| -------- | -------------------------------------- | 2101| 17700001 | The specified bundleName is not found. | 2102 2103**示例:** 2104 2105```ts 2106import bundleManager from '@ohos.bundle.bundleManager'; 2107import { BusinessError } from '@ohos.base'; 2108import hilog from '@ohos.hilog'; 2109let bundleName = "com.ohos.myapplication"; 2110 2111try { 2112 bundleManager.setApplicationEnabledSync(bundleName, false); 2113 hilog.info(0x0000, 'testTag', 'setApplicationEnabledSync successfully.'); 2114} catch (err) { 2115 let message = (err as BusinessError).message; 2116 hilog.error(0x0000, 'testTag', 'setApplicationEnabledSync failed: %{public}s', message); 2117} 2118``` 2119 2120### bundleManager.setAbilityEnabled 2121 2122setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean, callback: AsyncCallback\<void>): void; 2123 2124设置指定组件的禁用或使能状态,使用callback形式返回结果。 2125 2126**系统接口:** 此接口为系统接口。 2127 2128**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2129 2130**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2131 2132**参数:** 2133 2134| 参数名 | 类型 | 必填 | 说明 | 2135| -------- | ----------- | ---- | ------------------------------------- | 2136| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2137| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2138| callback | AsyncCallback\<void> | 是 | 回调函数,当设置组件禁用或使能状态成功时,err为null,否则为错误对象。 | 2139 2140**错误码:** 2141 2142以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2143 2144| 错误码ID | 错误信息 | 2145| -------- | ---------------------------------------| 2146| 17700001 | The specified bundleName is not found. | 2147| 17700003 | The specified abilityInfo is not found. | 2148 2149**示例:** 2150 2151```ts 2152import bundleManager from '@ohos.bundle.bundleManager'; 2153import { BusinessError } from '@ohos.base'; 2154import hilog from '@ohos.hilog'; 2155import Want from '@ohos.app.ability.Want'; 2156let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2157let userId = 100; 2158let want: Want = { 2159 bundleName : "com.example.myapplication", 2160 abilityName : "EntryAbility" 2161}; 2162 2163try { 2164 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2165 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2166 let info = abilitiesInfo[0]; 2167 2168 bundleManager.setAbilityEnabled(info, false, err => { 2169 if (err) { 2170 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2171 } else { 2172 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2173 } 2174 }); 2175 }).catch((err: BusinessError) => { 2176 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2177 }); 2178} catch (err) { 2179 let message = (err as BusinessError).message; 2180 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2181} 2182``` 2183 2184### bundleManager.setAbilityEnabled 2185 2186setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): Promise\<void>; 2187 2188设置指定组件的禁用或使能状态,使用Promise形式返回结果。 2189 2190**系统接口:** 此接口为系统接口。 2191 2192**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2193 2194**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2195 2196**参数:** 2197 2198| 参数名 | 类型 | 必填 | 说明 | 2199| -------- | ----------- | ---- | ------------------------------------- | 2200| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2201| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2202 2203**返回值:** 2204 2205| 类型 | 说明 | 2206| -------------- | --------------------------------- | 2207| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2208 2209**错误码:** 2210 2211以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2212 2213| 错误码ID | 错误信息 | 2214| -------- | -------------------------------------- | 2215| 17700001 | The specified bundleName is not found. | 2216| 17700003 | The specified abilityInfo is not found. | 2217 2218**示例:** 2219 2220```ts 2221import bundleManager from '@ohos.bundle.bundleManager'; 2222import { BusinessError } from '@ohos.base'; 2223import hilog from '@ohos.hilog'; 2224import Want from '@ohos.app.ability.Want'; 2225let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2226let userId = 100; 2227let want: Want = { 2228 bundleName : "com.example.myapplication", 2229 abilityName : "EntryAbility" 2230}; 2231 2232try { 2233 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2234 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2235 let info = abilitiesInfo[0]; 2236 2237 bundleManager.setAbilityEnabled(info, false).then(() => { 2238 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2239 }).catch((err: BusinessError) => { 2240 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2241 }); 2242 }).catch((err: BusinessError) => { 2243 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2244 }); 2245} catch (err) { 2246 let message = (err as BusinessError).message; 2247 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2248} 2249``` 2250 2251### bundleManager.setAbilityEnabledSync<sup>10+</sup> 2252 2253setAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): void; 2254 2255以同步方法设置指定组件的禁用或使能状态。 2256 2257**系统接口:** 此接口为系统接口。 2258 2259**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2260 2261**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2262 2263**参数:** 2264 2265| 参数名 | 类型 | 必填 | 说明 | 2266| -------- | ----------- | ---- | ------------------------------------- | 2267| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2268| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2269 2270**错误码:** 2271 2272以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2273 2274| 错误码ID | 错误信息 | 2275| -------- | ---------------------------------------| 2276| 17700001 | The specified bundleName is not found. | 2277| 17700003 | The specified abilityInfo is not found. | 2278 2279**示例:** 2280 2281```ts 2282import bundleManager from '@ohos.bundle.bundleManager'; 2283import { BusinessError } from '@ohos.base'; 2284import hilog from '@ohos.hilog'; 2285import Want from '@ohos.app.ability.Want'; 2286let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2287let userId = 100; 2288let want: Want = { 2289 bundleName : "com.example.myapplication", 2290 abilityName : "EntryAbility" 2291}; 2292 2293try { 2294 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2295 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2296 let info = abilitiesInfo[0]; 2297 2298 try { 2299 bundleManager.setAbilityEnabledSync(info, false); 2300 hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully."); 2301 } catch (err) { 2302 let message = (err as BusinessError).message; 2303 hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', message); 2304 } 2305 }).catch((err: BusinessError) => { 2306 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2307 }); 2308} catch (err) { 2309 let message = (err as BusinessError).message; 2310 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2311} 2312``` 2313 2314### bundleManager.isApplicationEnabled 2315 2316isApplicationEnabled(bundleName: string, callback: AsyncCallback\<boolean>): void; 2317 2318以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。 2319 2320**系统接口:** 此接口为系统接口。 2321 2322**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2323 2324**参数:** 2325 2326| 参数名 | 类型 | 必填 | 说明 | 2327| ---------- | ------ | ---- | -------------------------- | 2328| bundleName | string | 是 | 表示应用程序的bundleName。 | 2329| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。 | 2330 2331**错误码:** 2332 2333以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2334 2335| 错误码ID | 错误信息 | 2336| -------- | -------------------------------------- | 2337| 17700001 | The specified bundleName is not found. | 2338 2339**示例:** 2340 2341```ts 2342import bundleManager from '@ohos.bundle.bundleManager'; 2343import { BusinessError } from '@ohos.base'; 2344import hilog from '@ohos.hilog'; 2345let bundleName = 'com.example.myapplication'; 2346 2347try { 2348 bundleManager.isApplicationEnabled(bundleName, (err, data) => { 2349 if (err) { 2350 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message); 2351 } else { 2352 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data)); 2353 } 2354 }); 2355} catch (err) { 2356 let message = (err as BusinessError).message; 2357 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', message); 2358} 2359``` 2360 2361### bundleManager.isApplicationEnabled 2362 2363isApplicationEnabled(bundleName: string): Promise\<boolean>; 2364 2365以异步的方法获取指定应用的禁用或使能状态,使用Promise形式返回结果。 2366 2367**系统接口:** 此接口为系统接口。 2368 2369**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2370 2371**参数:** 2372 2373| 参数名 | 类型 | 必填 | 说明 | 2374| ---------- | ------ | ---- | -------------------------- | 2375| bundleName | string | 是 | 表示应用程序的bundleName。 | 2376 2377**返回值:** 2378 2379| 类型 | 说明 | 2380| ----------------- | ------------------------------------------------------------ | 2381| Promise\<boolean> | Promise对象,返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 | 2382 2383**错误码:** 2384 2385以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2386 2387| 错误码ID | 错误信息 | 2388| -------- | -------------------------------------- | 2389| 17700001 | The specified bundleName is not found. | 2390 2391**示例:** 2392 2393```ts 2394import bundleManager from '@ohos.bundle.bundleManager'; 2395import { BusinessError } from '@ohos.base'; 2396import hilog from '@ohos.hilog'; 2397let bundleName = 'com.example.myapplication'; 2398 2399try { 2400 bundleManager.isApplicationEnabled(bundleName).then((data) => { 2401 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2402 }).catch((err: BusinessError) => { 2403 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message); 2404 }); 2405} catch (err) { 2406 let message = (err as BusinessError).message; 2407 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', message); 2408} 2409``` 2410 2411### bundleManager.isApplicationEnabledSync<sup>10+</sup> 2412 2413isApplicationEnabledSync(bundleName: string): boolean; 2414 2415以同步方法获取指定应用的禁用或使能状态。 2416 2417**系统接口:** 此接口为系统接口。 2418 2419**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2420 2421**参数:** 2422 2423| 参数名 | 类型 | 必填 | 说明 | 2424| ---------- | ------ | ---- | -------------------------- | 2425| bundleName | string | 是 | 表示应用程序的bundleName。 | 2426 2427**返回值:** 2428 2429| 类型 | 说明 | 2430| ------- | ------------------------------------------------------------ | 2431| boolean | 返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 | 2432 2433**错误码:** 2434 2435以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2436 2437| 错误码ID | 错误信息 | 2438| -------- | -------------------------------------- | 2439| 17700001 | The specified bundleName is not found. | 2440 2441**示例:** 2442 2443```ts 2444import bundleManager from '@ohos.bundle.bundleManager'; 2445import { BusinessError } from '@ohos.base'; 2446import hilog from '@ohos.hilog'; 2447let bundleName = 'com.example.myapplication'; 2448 2449try { 2450 let data = bundleManager.isApplicationEnabledSync(bundleName); 2451 hilog.info(0x0000, 'testTag', 'isApplicationEnabledSync successfully: %{public}s', JSON.stringify(data)); 2452} catch (err) { 2453 let message = (err as BusinessError).message; 2454 hilog.error(0x0000, 'testTag', 'isApplicationEnabledSync failed: %{public}s', message); 2455} 2456``` 2457 2458### bundleManager.isAbilityEnabled 2459 2460isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), callback: AsyncCallback\<boolean>): void; 2461 2462以异步的方法获取指定组件的禁用或使能状态,使用callback形式返回结果。 2463 2464**系统接口:** 此接口为系统接口。 2465 2466**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2467 2468**参数:** 2469 2470| 参数名 | 类型 | 必填 | 说明 | 2471| ---- | ----------- | ---- | --------------------------- | 2472| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2473| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用组件为使能状态,返回false表示应用组件为禁用状态。 | 2474 2475**错误码:** 2476 2477以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2478 2479| 错误码ID | 错误信息 | 2480| -------- | --------------------------------------- | 2481| 17700001 | The specified bundleName is not found. | 2482| 17700003 | The specified abilityName is not found. | 2483 2484**示例:** 2485 2486```ts 2487import bundleManager from '@ohos.bundle.bundleManager'; 2488import { BusinessError } from '@ohos.base'; 2489import hilog from '@ohos.hilog'; 2490import Want from '@ohos.app.ability.Want'; 2491let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2492let userId = 100; 2493let want: Want = { 2494 bundleName : "com.example.myapplication", 2495 abilityName : "EntryAbility" 2496}; 2497 2498try { 2499 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2500 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2501 let info = abilitiesInfo[0]; 2502 2503 bundleManager.isAbilityEnabled(info, (err, data) => { 2504 if (err) { 2505 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message); 2506 } else { 2507 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data)); 2508 } 2509 }); 2510 }).catch((err: BusinessError) => { 2511 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2512 }); 2513} catch (err) { 2514 let message = (err as BusinessError).message; 2515 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2516} 2517``` 2518 2519### bundleManager.isAbilityEnabled 2520 2521isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Promise\<boolean>; 2522 2523以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。 2524 2525**系统接口:** 此接口为系统接口。 2526 2527**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2528 2529**参数:** 2530 2531| 参数名 | 类型 | 必填 | 说明 | 2532| ---- | ----------- | ---- | --------------------------- | 2533| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2534 2535**返回值:** 2536 2537| 类型 | 说明 | 2538| ----------------- | ------------------------------------------------------------ | 2539| Promise\<boolean> | Promise对象,返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 | 2540 2541**错误码:** 2542 2543以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2544 2545| 错误码ID | 错误信息 | 2546| -------- | --------------------------------------- | 2547| 17700001 | The specified bundleName is not found. | 2548| 17700003 | The specified abilityName is not found. | 2549 2550**示例:** 2551 2552```ts 2553import bundleManager from '@ohos.bundle.bundleManager'; 2554import { BusinessError } from '@ohos.base'; 2555import hilog from '@ohos.hilog'; 2556import Want from '@ohos.app.ability.Want'; 2557let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2558let userId = 100; 2559let want: Want = { 2560 bundleName : "com.example.myapplication", 2561 abilityName : "EntryAbility" 2562}; 2563 2564try { 2565 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2566 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2567 let info = abilitiesInfo[0]; 2568 2569 bundleManager.isAbilityEnabled(info).then((data) => { 2570 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2571 }).catch((err: BusinessError) => { 2572 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message); 2573 }); 2574 }).catch((err: BusinessError) => { 2575 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2576 }); 2577} catch (err) { 2578 let message = (err as BusinessError).message; 2579 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2580} 2581``` 2582 2583### bundleManager.isAbilityEnabledSync<sup>10+</sup> 2584 2585isAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): boolean; 2586 2587以同步方法获取指定组件的禁用或使能状态。 2588 2589**系统接口:** 此接口为系统接口。 2590 2591**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2592 2593**参数:** 2594 2595| 参数名 | 类型 | 必填 | 说明 | 2596| ---- | ----------- | ---- | --------------------------- | 2597| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2598 2599**返回值:** 2600 2601| 类型 | 说明 | 2602| ------- | ------------------------------------------------------------------- | 2603| boolean | 返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 | 2604 2605**错误码:** 2606 2607以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2608 2609| 错误码ID | 错误信息 | 2610| -------- | --------------------------------------- | 2611| 17700001 | The specified bundleName is not found. | 2612| 17700003 | The specified abilityName is not found. | 2613 2614**示例:** 2615 2616```ts 2617import bundleManager from '@ohos.bundle.bundleManager'; 2618import { BusinessError } from '@ohos.base'; 2619import hilog from '@ohos.hilog'; 2620import Want from '@ohos.app.ability.Want'; 2621let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2622let userId = 100; 2623let want: Want = { 2624 bundleName : "com.example.myapplication", 2625 abilityName : "EntryAbility" 2626}; 2627 2628try { 2629 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2630 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2631 let info = abilitiesInfo[0]; 2632 2633 try { 2634 let data = bundleManager.isAbilityEnabledSync(info); 2635 hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data)); 2636 } catch (err) { 2637 let message = (err as BusinessError).message; 2638 hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', message); 2639 } 2640 }).catch((err: BusinessError) => { 2641 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2642 }); 2643} catch (err) { 2644 let message = (err as BusinessError).message; 2645 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2646} 2647``` 2648 2649### bundleManager.getLaunchWantForBundle 2650 2651getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\<Want>): void; 2652 2653以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。 2654 2655**系统接口:** 此接口为系统接口。 2656 2657**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2658 2659**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2660 2661**参数:** 2662 2663| 参数名 | 类型 | 必填 | 说明 | 2664| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 2665| bundleName | string | 是 | 表示应用程序的bundleName。 | 2666| userId | number | 是 | 表示用户ID。 | 2667| callback | AsyncCallback\<Want> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 | 2668 2669**错误码:** 2670 2671以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2672 2673| 错误码ID | 错误信息 | 2674| -------- | --------------------------------------| 2675| 17700001 | The specified bundleName is not found. | 2676| 17700004 | The specified user ID is not found. | 2677| 17700026 | The specified bundle is disabled. | 2678 2679**示例:** 2680 2681```ts 2682import bundleManager from '@ohos.bundle.bundleManager'; 2683import { BusinessError } from '@ohos.base'; 2684import hilog from '@ohos.hilog'; 2685let bundleName = 'com.example.myapplication'; 2686let userId = 100; 2687 2688try { 2689 bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => { 2690 if (err) { 2691 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2692 } else { 2693 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 2694 } 2695 }); 2696} catch (err) { 2697 let message = (err as BusinessError).message; 2698 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message); 2699} 2700``` 2701 2702### bundleManager.getLaunchWantForBundle 2703 2704getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void; 2705 2706以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。 2707 2708**系统接口:** 此接口为系统接口。 2709 2710**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2711 2712**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2713 2714**参数:** 2715 2716| 参数名 | 类型 | 必填 | 说明 | 2717| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 2718| bundleName | string | 是 | 表示应用程序的bundleName。 | 2719| callback | AsyncCallback\<Want> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 | 2720 2721**错误码:** 2722 2723以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2724 2725| 错误码ID | 错误信息 | 2726| -------- | --------------------------------------| 2727| 17700001 | The specified bundleName is not found. | 2728| 17700026 | The specified bundle is disabled. | 2729 2730**示例:** 2731 2732```ts 2733import bundleManager from '@ohos.bundle.bundleManager'; 2734import { BusinessError } from '@ohos.base'; 2735import hilog from '@ohos.hilog'; 2736let bundleName = 'com.example.myapplication'; 2737 2738try { 2739 bundleManager.getLaunchWantForBundle(bundleName, (err, data) => { 2740 if (err) { 2741 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2742 } else { 2743 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 2744 } 2745 }); 2746} catch (err) { 2747 let message = (err as BusinessError).message; 2748 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message); 2749} 2750``` 2751 2752### bundleManager.getLaunchWantForBundle 2753 2754getLaunchWantForBundle(bundleName: string, userId?: number): Promise\<Want>; 2755 2756以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise形式返回结果。 2757 2758**系统接口:** 此接口为系统接口。 2759 2760**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2761 2762**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2763 2764**参数:** 2765 2766| 参数名 | 类型 | 必填 | 说明 | 2767| ---------- | ------ | ---- | ------------------------- | 2768| bundleName | string | 是 | 表示应用程序的bundleName。 | 2769| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 2770 2771**返回值:** 2772 2773| 类型 | 说明 | 2774| -------------- | ------------------------- | 2775| Promise\<Want> | Promise对象,返回Want对象。 | 2776 2777**错误码:** 2778 2779以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2780 2781| 错误码ID | 错误信息 | 2782| -------- | --------------------------------------| 2783| 17700001 | The specified bundleName is not found. | 2784| 17700004 | The specified user ID is not found. | 2785| 17700026 | The specified bundle is disabled. | 2786 2787**示例:** 2788 2789```ts 2790import bundleManager from '@ohos.bundle.bundleManager'; 2791import { BusinessError } from '@ohos.base'; 2792import hilog from '@ohos.hilog'; 2793let bundleName = 'com.example.myapplication'; 2794let userId = 100; 2795 2796try { 2797 bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => { 2798 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data)); 2799 }).catch((err: BusinessError) => { 2800 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message); 2801 }); 2802} catch (err) { 2803 let message = (err as BusinessError).message; 2804 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', message); 2805} 2806``` 2807 2808 2809### bundleManager.getLaunchWantForBundleSync<sup>10+</sup> 2810 2811getLaunchWantForBundleSync(bundleName: string, userId?: number): Want; 2812 2813以同步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数。 2814 2815**系统接口:** 此接口为系统接口。 2816 2817**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2818 2819**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2820 2821**参数:** 2822 2823| 参数名 | 类型 | 必填 | 说明 | 2824| ---------- | ------ | ---- | ------------------------- | 2825| bundleName | string | 是 | 表示应用程序的bundleName。 | 2826| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 2827 2828**返回值:** 2829 2830| 类型 | 说明 | 2831| -------------- | ------------------------- | 2832| Want | Want对象。 | 2833 2834**错误码:** 2835 2836以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2837 2838| 错误码ID | 错误信息 | 2839| -------- | --------------------------------------| 2840| 17700001 | The specified bundleName is not found. | 2841| 17700004 | The specified user ID is not found. | 2842| 17700026 | The specified bundle is disabled. | 2843 2844**示例:** 2845 2846```ts 2847import bundleManager from '@ohos.bundle.bundleManager'; 2848import { BusinessError } from '@ohos.base'; 2849import hilog from '@ohos.hilog'; 2850import Want from '@ohos.app.ability.Want'; 2851let bundleName = 'com.example.myapplication'; 2852let userId = 100; 2853 2854try { 2855 let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName, userId); 2856 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); 2857} catch (err) { 2858 let message = (err as BusinessError).message; 2859 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message); 2860} 2861``` 2862 2863```ts 2864import bundleManager from '@ohos.bundle.bundleManager'; 2865import { BusinessError } from '@ohos.base'; 2866import hilog from '@ohos.hilog'; 2867import Want from '@ohos.app.ability.Want'; 2868let bundleName = 'com.example.myapplication'; 2869let userId = 100; 2870 2871try { 2872 let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName); 2873 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); 2874} catch (err) { 2875 let message = (err as BusinessError).message; 2876 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message); 2877} 2878``` 2879 2880### bundleManager.getProfileByAbility 2881 2882getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void; 2883 2884以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。 2885 2886**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2887 2888**参数:** 2889 2890| 参数名 | 类型 | 必填 | 说明 | 2891| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 2892| moduleName | string | 是 | 表示应用程序的moduleName。 | 2893| abilityName | string | 是 | 表示应用程序的abilityName。 | 2894| metadataName | string | 是 | 表示应用程序的metadataName。 | 2895| callback | AsyncCallback<Array\<string>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 | 2896 2897**错误码:** 2898 2899以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2900 2901| 错误码ID | 错误信息 | 2902| -------- | ------------------------------------------------------------ | 2903| 17700002 | The specified moduleName is not existed. | 2904| 17700003 | The specified abilityName is not existed. | 2905| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2906| 17700026 | The specified bundle is disabled. | 2907| 17700029 | The specified ability is disabled. | 2908 2909**示例:** 2910 2911```ts 2912import bundleManager from '@ohos.bundle.bundleManager'; 2913import { BusinessError } from '@ohos.base'; 2914import hilog from '@ohos.hilog'; 2915let moduleName = 'entry'; 2916let abilityName = 'EntryAbility'; 2917let metadataName = 'com.example.myapplication.metadata'; 2918 2919try { 2920 bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => { 2921 if (err) { 2922 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2923 } else { 2924 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data)); 2925 } 2926 }); 2927} catch (err) { 2928 let message = (err as BusinessError).message; 2929 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message); 2930} 2931``` 2932 2933### bundleManager.getProfileByAbility 2934 2935getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string\>\>; 2936 2937以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。 2938 2939**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2940 2941**参数:** 2942 2943| 参数名 | 类型 | 必填 | 说明 | 2944| ------------ | ------ | ---- | -------------------------- | 2945| moduleName | string | 是 | 表示应用程序的moduleName。 | 2946| abilityName | string | 是 | 表示应用程序的abilityName。 | 2947| metadataName | string | 否 | 表示应用程序的metadataName,默认值为空。 | 2948 2949**返回值:** 2950 2951| 类型 | 说明 | 2952| ----------------------- | ------------------------------- | 2953| Promise<Array\<string>> | Promise对象,返回Array\<string>。 | 2954 2955**错误码:** 2956 2957以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 2958 2959| 错误码ID | 错误信息 | 2960| -------- | ------------------------------------------------------------ | 2961| 17700002 | The specified moduleName is not existed. | 2962| 17700003 | The specified abilityName is not existed. | 2963| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2964| 17700026 | The specified bundle is disabled. | 2965| 17700029 | The specified ability is disabled. | 2966 2967**示例:** 2968 2969```ts 2970import bundleManager from '@ohos.bundle.bundleManager'; 2971import { BusinessError } from '@ohos.base'; 2972import hilog from '@ohos.hilog'; 2973let moduleName = 'entry'; 2974let abilityName = 'EntryAbility'; 2975 2976try { 2977 bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => { 2978 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data)); 2979 }).catch((err: BusinessError) => { 2980 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2981 }); 2982} catch (err) { 2983 let message = (err as BusinessError).message; 2984 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message); 2985} 2986``` 2987 2988```ts 2989import bundleManager from '@ohos.bundle.bundleManager'; 2990import { BusinessError } from '@ohos.base'; 2991import hilog from '@ohos.hilog'; 2992let moduleName = 'entry'; 2993let abilityName = 'EntryAbility'; 2994let metadataName = 'com.example.myapplication.metadata'; 2995try { 2996 bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => { 2997 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data)); 2998 }).catch((err: BusinessError) => { 2999 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 3000 }); 3001} catch (err) { 3002 let message = (err as BusinessError).message; 3003 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message); 3004} 3005``` 3006 3007### bundleManager.getProfileByAbilitySync<sup>10+</sup> 3008 3009getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array\<string\>; 3010 3011以同步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,返回对象为string数组。 3012 3013**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3014 3015**参数:** 3016 3017| 参数名 | 类型 | 必填 | 说明 | 3018| ------------ | ------ | ---- | -------------------------- | 3019| moduleName | string | 是 | 表示应用程序的moduleName。 | 3020| abilityName | string | 是 | 表示应用程序的abilityName。 | 3021| metadataName | string | 否 | 表示应用程序的metadataName,默认值为空。 | 3022 3023**返回值:** 3024 3025| 类型 | 说明 | 3026| ----------------------- | ------------------------------- | 3027| Array\<string> | 数组对象,返回Array\<string>。 | 3028 3029**错误码:** 3030 3031以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3032 3033| 错误码ID | 错误信息 | 3034| -------- | ------------------------------------------------------------ | 3035| 17700002 | The specified moduleName is not existed. | 3036| 17700003 | The specified abilityName is not existed. | 3037| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3038| 17700026 | The specified bundle is disabled. | 3039| 17700029 | The specified ability is disabled. | 3040 3041**示例:** 3042 3043```ts 3044import bundleManager from '@ohos.bundle.bundleManager'; 3045import { BusinessError } from '@ohos.base'; 3046import hilog from '@ohos.hilog'; 3047let moduleName = 'entry'; 3048let abilityName = 'EntryAbility'; 3049 3050try { 3051 let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName); 3052 hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3053} catch (err) { 3054 let message = (err as BusinessError).message; 3055 hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message); 3056} 3057``` 3058 3059```ts 3060import bundleManager from '@ohos.bundle.bundleManager'; 3061import { BusinessError } from '@ohos.base'; 3062import hilog from '@ohos.hilog'; 3063let moduleName: string = 'entry'; 3064let abilityName: string = 'EntryAbility'; 3065let metadataName: string = 'com.example.myapplication.metadata'; 3066try { 3067 let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName, metadataName); 3068 hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3069} catch (err) { 3070 let message = (err as BusinessError).message; 3071 hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message); 3072} 3073``` 3074 3075### bundleManager.getProfileByExtensionAbility 3076 3077getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void; 3078 3079以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。 3080 3081**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3082 3083**参数:** 3084 3085| 参数名 | 类型 | 必填 | 说明 | 3086| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ | 3087| moduleName | string | 是 | 表示应用程序的moduleName。 | 3088| extensionAbilityName | string | 是 | 表示应用程序的extensionAbilityName。 | 3089| metadataName | string | 是 | 表示应用程序的metadataName。 | 3090| callback | AsyncCallback<Array\<string>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 | 3091 3092**错误码:** 3093 3094以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3095 3096| 错误码ID | 错误信息 | 3097| -------- | ------------------------------------------------------------ | 3098| 17700002 | The specified moduleName is not existed. | 3099| 17700003 | The specified extensionAbilityName not existed. | 3100| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3101| 17700026 | The specified bundle is disabled. | 3102 3103**示例:** 3104 3105```ts 3106import bundleManager from '@ohos.bundle.bundleManager'; 3107import { BusinessError } from '@ohos.base'; 3108import hilog from '@ohos.hilog'; 3109let moduleName = 'entry'; 3110let extensionAbilityName = 'com.example.myapplication.extension'; 3111let metadataName = 'com.example.myapplication.metadata'; 3112 3113try { 3114 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => { 3115 if (err) { 3116 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message); 3117 } else { 3118 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data)); 3119 } 3120 }); 3121} catch (err) { 3122 let message = (err as BusinessError).message; 3123 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', message); 3124} 3125``` 3126 3127### bundleManager.getProfileByExtensionAbility 3128 3129getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string\>\>; 3130 3131以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。 3132 3133**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3134 3135**参数:** 3136 3137| 参数名 | 类型 | 必填 | 说明 | 3138| -------------------- | ------ | ---- | ---------------------------------- | 3139| moduleName | string | 是 | 表示应用程序的moduleName。 | 3140| extensionAbilityName | string | 是 | 表示应用程序的extensionAbilityName。 | 3141| metadataName | string | 否 | 表示应用程序的metadataName,默认值为空。 | 3142 3143**返回值:** 3144 3145| 类型 | 说明 | 3146| ----------------------- | ----------------------------------- | 3147| Promise<Array\<string>> | Promise对象,返回Array\<string>对象。 | 3148 3149**错误码:** 3150 3151以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3152 3153| 错误码ID | 错误信息 | 3154| -------- | ------------------------------------------------------------ | 3155| 17700002 | The specified moduleName is not existed. | 3156| 17700003 | The specified extensionAbilityName not existed. | 3157| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3158| 17700026 | The specified bundle is disabled. | 3159 3160**示例:** 3161 3162```ts 3163import bundleManager from '@ohos.bundle.bundleManager'; 3164import { BusinessError } from '@ohos.base'; 3165import hilog from '@ohos.hilog'; 3166let moduleName = 'entry'; 3167let extensionAbilityName = 'com.example.myapplication.extension'; 3168let metadataName = 'com.example.myapplication.metadata'; 3169 3170try { 3171 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => { 3172 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data)); 3173 }).catch((err: BusinessError) => { 3174 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 3175 }); 3176} catch (err) { 3177 let message = (err as BusinessError).message; 3178 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message); 3179} 3180 3181try { 3182 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => { 3183 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data)); 3184 }).catch((err: BusinessError) => { 3185 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 3186 }); 3187} catch (err) { 3188 let message = (err as BusinessError).message; 3189 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message); 3190} 3191``` 3192 3193### bundleManager.getProfileByExtensionAbilitySync<sup>10+</sup> 3194 3195getProfileByExtensionAbilitySync(moduleName: string, extensionAbilityName: string, metadataName?: string): Array\<string\>; 3196 3197以同步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,返回对象为string数组。 3198 3199**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3200 3201**参数:** 3202 3203| 参数名 | 类型 | 必填 | 说明 | 3204| -------------------- | ------ | ---- | ---------------------------------- | 3205| moduleName | string | 是 | 表示应用程序的moduleName。 | 3206| extensionAbilityName | string | 是 | 表示应用程序的extensionAbilityName。 | 3207| metadataName | string | 否 | 表示应用程序的metadataName,默认值为空。 | 3208 3209**返回值:** 3210 3211| 类型 | 说明 | 3212| ----------------------- | ----------------------------------- | 3213| Array\<string> | 返回Array\<string>对象。 | 3214 3215**错误码:** 3216 3217以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3218 3219| 错误码ID | 错误信息 | 3220| -------- | ------------------------------------------------------------ | 3221| 17700002 | The specified moduleName is not existed. | 3222| 17700003 | The specified extensionAbilityName not existed. | 3223| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3224| 17700026 | The specified bundle is disabled. | 3225 3226**示例:** 3227 3228```ts 3229import bundleManager from '@ohos.bundle.bundleManager'; 3230import { BusinessError } from '@ohos.base'; 3231import hilog from '@ohos.hilog'; 3232let moduleName = 'entry'; 3233let extensionAbilityName = 'com.example.myapplication.extension'; 3234let metadataName = 'com.example.myapplication.metadata'; 3235 3236try { 3237 let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName); 3238 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3239} catch (err) { 3240 let message = (err as BusinessError).message; 3241 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message); 3242} 3243 3244try { 3245 let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName, metadataName); 3246 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3247} catch (err) { 3248 let message = (err as BusinessError).message; 3249 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message); 3250} 3251``` 3252 3253### bundleManager.getPermissionDef 3254 3255getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void; 3256 3257以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。 3258 3259**系统接口:** 此接口为系统接口。 3260 3261**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3262 3263**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3264 3265**参数:** 3266 3267| 参数名 | 类型 | 必填 | 说明 | 3268| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3269| permissionName | string | 是 | 表示权限名称。 | 3270| callback | AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<PermissionDef>;否则为错误对象。 | 3271 3272**错误码:** 3273 3274以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3275 3276| 错误码ID | 错误信息 | 3277| -------- | ------------------------------------- | 3278| 17700006 | The specified permission is not found. | 3279 3280**示例:** 3281 3282```ts 3283import bundleManager from '@ohos.bundle.bundleManager'; 3284import { BusinessError } from '@ohos.base'; 3285import hilog from '@ohos.hilog'; 3286let permission = "ohos.permission.GET_BUNDLE_INFO"; 3287try { 3288 bundleManager.getPermissionDef(permission, (err, data) => { 3289 if (err) { 3290 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message); 3291 } else { 3292 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data)); 3293 } 3294 }); 3295} catch (err) { 3296 let message = (err as BusinessError).message; 3297 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', message); 3298} 3299``` 3300 3301### bundleManager.getPermissionDef 3302 3303getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>; 3304 3305以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise形式返回结果。 3306 3307**系统接口:** 此接口为系统接口。 3308 3309**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3310 3311**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3312 3313**参数:** 3314 3315| 参数名 | 类型 | 必填 | 说明 | 3316| -------------- | ------ | ---- | -------------- | 3317| permissionName | string | 是 | 表示权限参数名。 | 3318 3319**返回值:** 3320 3321| 类型 | 说明 | 3322| ------------------------------------------------------------ | ------------------------------------------ | 3323| Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | Promise对象,返回Array\<PermissionDef>对象。 | 3324 3325**错误码:** 3326 3327以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3328 3329| 错误码ID | 错误信息 | 3330| -------- | ------------------------------------- | 3331| 17700006 | The specified permission is not found. | 3332 3333**示例:** 3334 3335```ts 3336import bundleManager from '@ohos.bundle.bundleManager'; 3337import { BusinessError } from '@ohos.base'; 3338import hilog from '@ohos.hilog'; 3339let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 3340try { 3341 bundleManager.getPermissionDef(permissionName).then((data) => { 3342 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data)); 3343 }).catch((err: BusinessError) => { 3344 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message); 3345 }); 3346} catch (err) { 3347 let message = (err as BusinessError).message; 3348 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', message); 3349} 3350``` 3351 3352### bundleManager.getPermissionDefSync<sup>10+</sup> 3353 3354getPermissionDefSync(permissionName: string): [PermissionDef](js-apis-bundleManager-permissionDef.md); 3355 3356以同步方法根据给定的permissionName获取权限定义结构体PermissionDef信息。 3357 3358**系统接口:** 此接口为系统接口。 3359 3360**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3361 3362**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3363 3364**参数:** 3365 3366| 参数名 | 类型 | 必填 | 说明 | 3367| -------------- | ------ | ---- | -------------- | 3368| permissionName | string | 是 | 表示权限参数名。 | 3369 3370**返回值:** 3371 3372| 类型 | 说明 | 3373| ------------------------------------------------------------ | ------------------------------------------ | 3374|[PermissionDef](js-apis-bundleManager-permissionDef.md) | PermissionDef对象。 | 3375 3376**错误码:** 3377 3378以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3379 3380| 错误码ID | 错误信息 | 3381| -------- | ------------------------------------- | 3382| 17700006 | The specified permission is not found. | 3383 3384**示例:** 3385 3386```ts 3387import bundleManager from '@ohos.bundle.bundleManager'; 3388import { BusinessError } from '@ohos.base'; 3389import hilog from '@ohos.hilog'; 3390let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 3391try { 3392 let PermissionDef = bundleManager.getPermissionDefSync(permissionName); 3393 hilog.info(0x0000, 'testTag', 'getPermissionDefSync successfully. Data: %{public}s', JSON.stringify(PermissionDef)); 3394} catch (err) { 3395 let message = (err as BusinessError).message; 3396 hilog.error(0x0000, 'testTag', 'getPermissionDefSync failed. Cause: %{public}s', message); 3397} 3398``` 3399 3400### bundleManager.getAbilityLabel 3401 3402getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<string>): void; 3403 3404以异步的方法获取指定bundleName、moduleName和abilityName的label,使用callback形式返回结果。 3405 3406**系统接口:** 此接口为系统接口。 3407 3408**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3409 3410**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 3411 3412**参数:** 3413 3414| 参数名 | 类型 | 必填 | 说明 | 3415| ----------- | ---------------------- | ---- | ------------------------------------------------------------ | 3416| bundleName | string | 是 | 表示应用程序的bundleName。 | 3417| moduleName | string | 是 | 表示应用程序的moduleName。 | 3418| abilityName | string | 是 | 表示应用程序的abilityName。 | 3419| callback | AsyncCallback\<string> | 是 | 回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。 | 3420 3421**错误码:** 3422 3423以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3424 3425| 错误码ID | 错误信息 | 3426| -------- | -------------------------------------- | 3427| 17700001 | The specified bundleName is not found. | 3428| 17700002 | The specified moduleName is not found. | 3429| 17700003 | The specified abilityName is not found. | 3430| 17700026 | The specified bundle is disabled. | 3431| 17700029 | The specified ability is disabled. | 3432 3433**示例:** 3434 3435```ts 3436import bundleManager from '@ohos.bundle.bundleManager'; 3437import { BusinessError } from '@ohos.base'; 3438import hilog from '@ohos.hilog'; 3439let bundleName = 'com.example.myapplication'; 3440let moduleName = 'entry'; 3441let abilityName = 'EntryAbility'; 3442 3443try { 3444 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => { 3445 if (err) { 3446 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message); 3447 } else { 3448 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data)); 3449 } 3450 }); 3451} catch (err) { 3452 let message = (err as BusinessError).message; 3453 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', message); 3454} 3455``` 3456 3457### bundleManager.getAbilityLabel 3458 3459getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string>; 3460 3461以异步的方法获取指定bundleName、moduleName和abilityName的label,使用Promise形式返回结果。 3462 3463**系统接口:** 此接口为系统接口。 3464 3465**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3466 3467**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 3468 3469**参数:** 3470 3471| 参数名 | 类型 | 必填 | 说明 | 3472| ----------- | ------ | ---- | ------------------------- | 3473| bundleName | string | 是 | 表示应用程序的bundleName。 | 3474| moduleName | string | 是 | 表示应用程序的moduleName。 | 3475| abilityName | string | 是 | 表示应用程序的abilityName。 | 3476 3477**返回值:** 3478 3479| 类型 | 说明 | 3480| ---------------- | ----------------------------------- | 3481| Promise\<string> | Promise对象,返回指定组件的Lablel值。 | 3482 3483**错误码:** 3484 3485以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3486 3487| 错误码ID | 错误信息 | 3488| -------- | --------------------------------------- | 3489| 17700001 | The specified bundleName is not found. | 3490| 17700002 | The specified moduleName is not found. | 3491| 17700003 | The specified abilityName is not found. | 3492| 17700026 | The specified bundle is disabled. | 3493| 17700029 | The specified ability is disabled. | 3494 3495**示例:** 3496 3497```ts 3498import bundleManager from '@ohos.bundle.bundleManager'; 3499import { BusinessError } from '@ohos.base'; 3500import hilog from '@ohos.hilog'; 3501let bundleName = 'com.example.myapplication'; 3502let moduleName = 'entry'; 3503let abilityName = 'EntryAbility'; 3504 3505try { 3506 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => { 3507 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data)); 3508 }).catch((err: BusinessError) => { 3509 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message); 3510 }); 3511} catch (err) { 3512 let message = (err as BusinessError).message; 3513 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', message); 3514} 3515``` 3516 3517### bundleManager.getAbilityLabelSync<sup>10+</sup> 3518 3519getAbilityLabelSync(bundleName: string, moduleName: string, abilityName: string): string; 3520 3521以同步的方法获取指定bundleName、moduleName和abilityName的label。 3522 3523**系统接口:** 此接口为系统接口。 3524 3525**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3526 3527**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 3528 3529**参数:** 3530 3531| 参数名 | 类型 | 必填 | 说明 | 3532| ----------- | ------ | ---- | ------------------------- | 3533| bundleName | string | 是 | 表示应用程序的bundleName。 | 3534| moduleName | string | 是 | 表示应用程序的moduleName。 | 3535| abilityName | string | 是 | 表示应用程序的abilityName。 | 3536 3537**返回值:** 3538 3539| 类型 | 说明 | 3540| ---------------- | ----------------------------------- | 3541| string | 指定组件的Lablel值。 | 3542 3543**错误码:** 3544 3545以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3546 3547| 错误码ID | 错误信息 | 3548| -------- | --------------------------------------- | 3549| 17700001 | The specified bundleName is not found. | 3550| 17700002 | The specified moduleName is not found. | 3551| 17700003 | The specified abilityName is not found. | 3552| 17700026 | The specified bundle is disabled. | 3553| 17700029 | The specified ability is disabled. | 3554 3555**示例:** 3556 3557```ts 3558import bundleManager from '@ohos.bundle.bundleManager'; 3559import { BusinessError } from '@ohos.base'; 3560import hilog from '@ohos.hilog'; 3561let bundleName = 'com.example.myapplication'; 3562let moduleName = 'entry'; 3563let abilityName = 'EntryAbility'; 3564 3565try { 3566 let abilityLabel = bundleManager.getAbilityLabelSync(bundleName, moduleName, abilityName); 3567 hilog.info(0x0000, 'testTag', 'getAbilityLabelSync successfully. Data: %{public}s', abilityLabel); 3568} catch (err) { 3569 let message = (err as BusinessError).message; 3570 hilog.error(0x0000, 'testTag', 'getAbilityLabelSync failed. Cause: %{public}s', message); 3571} 3572``` 3573 3574### bundleManager.getApplicationInfoSync 3575 3576getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md); 3577 3578以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。 3579 3580**系统接口:** 此接口为系统接口。 3581 3582**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3583 3584**系统能力:** SystemCapability.BundleManager.BundleFramework.Core。 3585 3586**参数:** 3587 3588| 参数名 | 类型 | 必填 | 说明 | 3589| ----------- | ------ | ---- | ----------------------------------------------------------| 3590| bundleName | string | 是 | 表示应用程序的bundleName。 | 3591| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | 3592| userId | number | 是 | 表示用户ID。 | 3593 3594**返回值:** 3595 3596| 类型 | 说明 | 3597| --------------- | ------------------------- | 3598| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | 3599 3600**错误码:** 3601 3602以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3603 3604| 错误码ID | 错误信息 | 3605| -------- | -------------------------------------- | 3606| 17700001 | The specified bundleName is not found. | 3607| 17700004 | The specified user ID is not found. | 3608| 17700026 | The specified bundle is disabled. | 3609 3610**示例:** 3611 3612```ts 3613import bundleManager from '@ohos.bundle.bundleManager'; 3614import { BusinessError } from '@ohos.base'; 3615import hilog from '@ohos.hilog'; 3616let bundleName = 'com.example.myapplication'; 3617let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 3618let userId = 100; 3619 3620try { 3621 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId); 3622 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 3623} catch (err) { 3624 let message = (err as BusinessError).message; 3625 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message); 3626} 3627``` 3628 3629### bundleManager.getApplicationInfoSync 3630 3631getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md); 3632 3633以同步方法根据给定的bundleName、applicationFlags获取ApplicationInfo。 3634 3635**系统接口:** 此接口为系统接口。 3636 3637**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3638 3639**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3640 3641**参数:** 3642 3643| 参数名 | 类型 | 必填 | 说明 | 3644| ---------------- | -------------------------- | ---- | ----------------------------------------------------- | 3645| bundleName | string | 是 | 表示应用程序的bundleName。 | 3646| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | 3647 3648**返回值:** 3649 3650| 类型 | 说明 | 3651| ----------------------------------------------------------- | ------------------------- | 3652| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | 3653 3654**错误码:** 3655 3656以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3657 3658| 错误码ID | 错误信息 | 3659| -------- | -------------------------------------- | 3660| 17700001 | The specified bundleName is not found. | 3661| 17700026 | The specified bundle is disabled. | 3662 3663**示例:** 3664 3665```ts 3666import bundleManager from '@ohos.bundle.bundleManager'; 3667import { BusinessError } from '@ohos.base'; 3668import hilog from '@ohos.hilog'; 3669let bundleName = 'com.example.myapplication'; 3670let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 3671 3672try { 3673 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags); 3674 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 3675} catch (err) { 3676 let message = (err as BusinessError).message; 3677 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message); 3678} 3679``` 3680 3681### bundleManager.getBundleInfoSync 3682 3683getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md); 3684 3685以同步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo。 3686 3687**系统接口:** 此接口为系统接口。 3688 3689**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3690 3691**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3692 3693**参数:** 3694 3695| 参数名 | 类型 | 必填 | 说明 | 3696| ----------- | ------ | ---- | -------------------------------------------------------- | 3697| bundleName | string | 是 | 表示应用程序的bundleName。 | 3698| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | 3699| userId | number | 是 | 表示用户ID。 | 3700 3701**返回值:** 3702 3703| 类型 | 说明 | 3704| ---------- | -------------------- | 3705| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 3706 3707**错误码:** 3708 3709以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3710 3711| 错误码ID | 错误信息 | 3712| -------- | ------------------------------------- | 3713| 17700001 | The specified bundleName is not found. | 3714| 17700004 | The specified user ID is not found. | 3715| 17700026 | The specified bundle is disabled. | 3716 3717**示例:** 3718 3719```ts 3720import bundleManager from '@ohos.bundle.bundleManager'; 3721import { BusinessError } from '@ohos.base'; 3722import hilog from '@ohos.hilog'; 3723let bundleName = 'com.example.myapplication'; 3724let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 3725let userId = 100; 3726 3727try { 3728 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId); 3729 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 3730} catch (err) { 3731 let message = (err as BusinessError).message; 3732 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message); 3733} 3734``` 3735 3736### bundleManager.getBundleInfoSync 3737 3738getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md); 3739 3740以同步方法根据给定的bundleName、bundleFlags获取BundleInfo。 3741 3742**系统接口:** 此接口为系统接口。 3743 3744**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3745 3746**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3747 3748**参数:** 3749 3750| 参数名 | 类型 | 必填 | 说明 | 3751| ----------- | --------------------- | ---- | ------------------------------------------------------ | 3752| bundleName | string | 是 | 表示应用程序的bundleName。 | 3753| bundleFlags | [number](#bundleflag) | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | 3754 3755**返回值:** 3756 3757| 类型 | 说明 | 3758| ------------------------------------------------- | -------------------- | 3759| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 3760 3761**错误码:** 3762 3763以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3764 3765| 错误码ID | 错误信息 | 3766| -------- | -------------------------------------- | 3767| 17700001 | The specified bundleName is not found. | 3768| 17700026 | The specified bundle is disabled. | 3769 3770**示例:** 3771 3772```ts 3773import bundleManager from '@ohos.bundle.bundleManager'; 3774import { BusinessError } from '@ohos.base'; 3775import hilog from '@ohos.hilog'; 3776let bundleName = 'com.example.myapplication'; 3777let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 3778try { 3779 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags); 3780 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 3781} catch (err) { 3782 let message = (err as BusinessError).message; 3783 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message); 3784} 3785``` 3786 3787### bundleManager.getSharedBundleInfo<sup>10+</sup> 3788 3789getSharedBundleInfo(bundleName: string, moduleName: string, callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void; 3790 3791以异步的方法获取指定的共享包信息,使用callback形式返回结果。 3792 3793**系统接口:** 此接口为系统接口。 3794 3795**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3796 3797**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3798 3799**参数:** 3800 3801| 参数名 | 类型 | 必填 | 说明 | 3802| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3803| bundleName | string | 是 | 表示应用程序的bundleName。 | 3804| moduleName | string | 是 | 表示被查询的module的name。 | 3805| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | 是 | 回调函数,当获取成功时,err为null,data为获取的指定共享包信息。 | 3806 3807**错误码:** 3808 3809以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3810 3811| 错误码ID | 错误信息 | 3812| -------- | -------------------------------------- | 3813| 17700001 | The specified bundleName is not found. | 3814| 17700002 | The specified moduleName is not found. | 3815 3816**示例:** 3817 3818```ts 3819import bundleManager from '@ohos.bundle.bundleManager'; 3820import { BusinessError } from '@ohos.base'; 3821import hilog from '@ohos.hilog'; 3822let bundleName = 'com.example.myapplication'; 3823let moduleName = 'library'; 3824 3825try { 3826 bundleManager.getSharedBundleInfo(bundleName, moduleName, (err, data) => { 3827 if (err) { 3828 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', err.message); 3829 } else { 3830 hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully: %{public}s', JSON.stringify(data)); 3831 } 3832 }); 3833} catch (err) { 3834 let message = (err as BusinessError).message; 3835 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', message); 3836} 3837``` 3838 3839### bundleManager.getSharedBundleInfo<sup>10+</sup> 3840 3841getSharedBundleInfo(bundleName: string, moduleName: string): Promise\<Array\<SharedBundleInfo\>\>; 3842 3843以异步的方法获取指定的共享包信息,使用Promise形式返回结果。 3844 3845**系统接口:** 此接口为系统接口 3846 3847**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3848 3849**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3850 3851**参数:** 3852 3853| 参数名 | 类型 | 必填 | 说明 | 3854| ---------- | ------ | ---- | -------------------------- | 3855| bundleName | string | 是 | 表示应用程序的bundleName。 | 3856| moduleName | string | 是 | 表示被查询的module的name。 | 3857 3858**返回值:** 3859 3860| 类型 | 说明 | 3861| ------------------------------------------------------------ | ----------------------------------- | 3862| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Promise对象,返回指定的共享包信息。 | 3863 3864**错误码:** 3865 3866以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3867 3868| 错误码ID | 错误信息 | 3869| -------- | -------------------------------------- | 3870| 17700001 | The specified bundleName is not found. | 3871| 17700002 | The specified moduleName is not found. | 3872 3873**示例:** 3874 3875```ts 3876import bundleManager from '@ohos.bundle.bundleManager'; 3877import { BusinessError } from '@ohos.base'; 3878import hilog from '@ohos.hilog'; 3879let bundleName = 'com.example.myapplication'; 3880let moduleName = 'library'; 3881 3882try { 3883 bundleManager.getSharedBundleInfo(bundleName, moduleName).then((data) => { 3884 hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 3885 }).catch((err: BusinessError) => { 3886 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', err.message); 3887 }); 3888} catch (err) { 3889 let message = (err as BusinessError).message; 3890 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', message); 3891} 3892``` 3893 3894### bundleManager.getAllSharedBundleInfo<sup>10+</sup> 3895 3896getAllSharedBundleInfo(callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void; 3897 3898以异步的方法获取所有的共享包信息,使用callback形式返回结果。 3899 3900**系统接口:** 此接口为系统接口。 3901 3902**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3903 3904**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3905 3906**参数:** 3907 3908| 参数名 | 类型 | 必填 | 说明 | 3909| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3910| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | 是 | 回调函数,当获取成功时,err为null,data为获所有的共享包信息。 | 3911 3912**示例:** 3913 3914```ts 3915import bundleManager from '@ohos.bundle.bundleManager'; 3916import { BusinessError } from '@ohos.base'; 3917import hilog from '@ohos.hilog'; 3918 3919try { 3920 bundleManager.getAllSharedBundleInfo((err, data) => { 3921 if (err) { 3922 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', err.message); 3923 } else { 3924 hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully: %{public}s', JSON.stringify(data)); 3925 } 3926 }); 3927} catch (err) { 3928 let message = (err as BusinessError).message; 3929 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', message); 3930} 3931``` 3932 3933### bundleManager.getAllSharedBundleInfo<sup>10+</sup> 3934 3935getAllSharedBundleInfo(): Promise\<Array\<SharedBundleInfo\>\>; 3936 3937以异步的方法获取所有的共享包信息,使用Promise形式返回结果。 3938 3939**系统接口:** 此接口为系统接口 3940 3941**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3942 3943**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3944 3945**返回值:** 3946 3947| 类型 | 说明 | 3948| ------------------------------------------------------------ | ----------------------------------- | 3949| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Promise对象,返回所有的共享包信息。 | 3950 3951**示例:** 3952 3953```ts 3954import bundleManager from '@ohos.bundle.bundleManager'; 3955import { BusinessError } from '@ohos.base'; 3956import hilog from '@ohos.hilog'; 3957 3958try { 3959 bundleManager.getAllSharedBundleInfo().then((data) => { 3960 hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 3961 }).catch((err: BusinessError) => { 3962 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', err.message); 3963 }); 3964} catch (err) { 3965 let message = (err as BusinessError).message; 3966 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', message); 3967} 3968``` 3969 3970### bundleManager.getAppProvisionInfo<sup>10+</sup> 3971 3972getAppProvisionInfo(bundleName: string, callback: AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\>): void; 3973 3974以异步的方法获取指定bundleName的provision配置文件信息,使用callback形式返回结果。 3975 3976**系统接口:** 此接口为系统接口。 3977 3978**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3979 3980**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3981 3982**参数:** 3983 3984| 参数名 | 类型 | 必填 | 说明 | 3985| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3986| bundleName | string | 是 | 指定应用的bundleName。 | 3987| callback | AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> | 是 | 回调函数,当获取成功时,err为null,data为指定bundleName的provision配置文件信息。 | 3988 3989**错误码:** 3990 3991以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 3992 3993| 错误码ID | 错误信息 | 3994| -------- | -------------------------------------- | 3995| 17700001 | The specified bundleName is not found. | 3996 3997**示例:** 3998 3999```ts 4000import bundleManager from '@ohos.bundle.bundleManager'; 4001import { BusinessError } from '@ohos.base'; 4002import hilog from '@ohos.hilog'; 4003let bundleName = "com.ohos.myapplication"; 4004 4005try { 4006 bundleManager.getAppProvisionInfo(bundleName, (err, data) => { 4007 if (err) { 4008 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message); 4009 } else { 4010 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data)); 4011 } 4012 }); 4013} catch (err) { 4014 let message = (err as BusinessError).message; 4015 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message); 4016} 4017``` 4018 4019### bundleManager.getAppProvisionInfo<sup>10+</sup> 4020 4021getAppProvisionInfo(bundleName: string, userId: number, callback: AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\>): void; 4022 4023以异步的方法获取指定bundleName和userId的provision配置文件信息,使用callback形式返回结果。 4024 4025**系统接口:** 此接口为系统接口。 4026 4027**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4028 4029**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4030 4031**参数:** 4032 4033| 参数名 | 类型 | 必填 | 说明 | 4034| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4035| bundleName | string | 是 | 指定应用的bundleName。 | 4036| userId | number | 是 | 指定用户ID, 可以通过接口[getOsAccountLocalId](js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | 4037| callback | AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> | 是 | 回调函数,当获取成功时,err为null,data为指定bundleName的provision配置文件信息。 | 4038 4039 4040**错误码:** 4041 4042以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 4043 4044| 错误码ID | 错误信息 | 4045| -------- | -------------------------------------- | 4046| 17700001 | The specified bundleName is not found. | 4047| 17700004 | The specified user ID is not found. | 4048 4049**示例:** 4050 4051```ts 4052import bundleManager from '@ohos.bundle.bundleManager'; 4053import { BusinessError } from '@ohos.base'; 4054import hilog from '@ohos.hilog'; 4055let bundleName = "com.ohos.myapplication"; 4056let userId = 100; 4057 4058try { 4059 bundleManager.getAppProvisionInfo(bundleName, userId, (err, data) => { 4060 if (err) { 4061 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message); 4062 } else { 4063 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data)); 4064 } 4065 }); 4066} catch (err) { 4067 let message = (err as BusinessError).message; 4068 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message); 4069} 4070``` 4071 4072### bundleManager.getAppProvisionInfo<sup>10+</sup> 4073 4074getAppProvisionInfo(bundleName: string, userId?: number): Promise\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\>; 4075 4076以异步的方法根据bundleName和userId获取应用的provision配置文件信息,使用Promise形式返回结果。 4077 4078**系统接口:** 此接口为系统接口 4079 4080**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4081 4082**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4083 4084**参数:** 4085 4086| 参数名 | 类型 | 必填 | 说明 | 4087| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4088| bundleName | string | 是 | 指定的bundleName。 | 4089| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口[getOsAccountLocalId](js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | 4090 4091 4092**返回值:** 4093 4094| 类型 | 说明 | 4095| ------------------------------------------------------------ | ----------------------------------- | 4096| Promise\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> | Promise对象,返回应用的provision配置文件信息。 | 4097 4098**错误码:** 4099 4100以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 4101 4102| 错误码ID | 错误信息 | 4103| -------- | -------------------------------------- | 4104| 17700001 | The specified bundleName is not found. | 4105| 17700004 | The specified user ID is not found. | 4106 4107**示例:** 4108 4109```ts 4110import bundleManager from '@ohos.bundle.bundleManager'; 4111import { BusinessError } from '@ohos.base'; 4112import hilog from '@ohos.hilog'; 4113let bundleName = "com.ohos.myapplication"; 4114let userId = 100; 4115 4116try { 4117 bundleManager.getAppProvisionInfo(bundleName).then((data) => { 4118 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data)); 4119 }).catch((err: BusinessError) => { 4120 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message); 4121 }); 4122} catch (err) { 4123 let message = (err as BusinessError).message; 4124 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message); 4125} 4126 4127try { 4128 bundleManager.getAppProvisionInfo(bundleName, userId).then((data) => { 4129 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data)); 4130 }).catch((err: BusinessError) => { 4131 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message); 4132 }); 4133} catch (err) { 4134 let message = (err as BusinessError).message; 4135 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message); 4136} 4137``` 4138 4139### bundleManager.getAppProvisionInfoSync<sup>10+</sup> 4140 4141getAppProvisionInfoSync(bundleName: string, userId?: number): AppProvisionInfo; 4142 4143以同步方法根据bundleName和userId获取应用的provision配置文件信息并返回结果。 4144 4145**系统接口:** 此接口为系统接口 4146 4147**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4148 4149**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4150 4151**参数:** 4152 4153| 参数名 | 类型 | 必填 | 说明 | 4154| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4155| bundleName | string | 是 | 指定的bundleName。 | 4156| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口[getOsAccountLocalId](js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | 4157 4158 4159**返回值:** 4160 4161| 类型 | 说明 | 4162| ------------------------------------------------------------ | ----------------------------------- | 4163| [AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md) | AppProvisionInfo对象,返回应用的provision配置文件信息。 | 4164 4165**错误码:** 4166 4167以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 4168 4169| 错误码ID | 错误信息 | 4170| -------- | -------------------------------------- | 4171| 17700001 | The specified bundleName is not found. | 4172| 17700004 | The specified user ID is not found. | 4173 4174**示例:** 4175 4176```ts 4177import bundleManager from '@ohos.bundle.bundleManager'; 4178import { BusinessError } from '@ohos.base'; 4179import hilog from '@ohos.hilog'; 4180let bundleName = "com.ohos.myapplication"; 4181let userId = 100; 4182 4183try { 4184 let data = bundleManager.getAppProvisionInfoSync(bundleName); 4185 hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4186} catch (err) { 4187 let message = (err as BusinessError).message; 4188 hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message); 4189} 4190 4191try { 4192 let data = bundleManager.getAppProvisionInfoSync(bundleName, userId); 4193 hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4194} catch (err) { 4195 let message = (err as BusinessError).message; 4196 hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message); 4197} 4198``` 4199 4200### bundleManager.getSpecifiedDistributionType<sup>10+</sup> 4201getSpecifiedDistributionType(bundleName: string): string; 4202 4203以同步的方法查询指定bundleName的分发类型,该返回值是在调用install接口时传入的[InstallParam](./js-apis-installer.md#installparam)中的specifiedDistributionType字段。 4204 4205**系统接口:** 此接口为系统接口。 4206 4207**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4208 4209**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4210 4211**参数:** 4212 4213| 参数名 | 类型 | 必填 | 说明 | 4214| -------------- | ----------------------------------- | ---- | ---------------------------- | 4215| bundleName | string | 是 | 指定的bundleName。 | 4216 4217**返回值:** 4218 4219| 类型 | 说明 | 4220| ------------- | -------------------------------------- | 4221| string | 返回指定bundleName的分发类型。 | 4222 4223**错误码:** 4224 4225以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 4226 4227| 错误码ID | 错误信息 | 4228| -------- | ------------------------------------------------------------ | 4229| 17700001 | The specified bundleName is not found. | 4230 4231**示例:** 4232```ts 4233import bundleManager from '@ohos.bundle.bundleManager'; 4234import { BusinessError } from '@ohos.base'; 4235let bundleName = "com.example.myapplication"; 4236 4237try { 4238 let type = bundleManager.getSpecifiedDistributionType(bundleName); 4239 console.info('getSpecifiedDistributionType successfully, type:' + type); 4240} catch (error) { 4241 let message = (error as BusinessError).message; 4242 console.error('getSpecifiedDistributionType failed. Cause: ' + message); 4243} 4244``` 4245 4246 4247### bundleManager.getAdditionalInfo<sup>10+</sup> 4248 4249getAdditionalInfo(bundleName: string): string; 4250 4251以同步接口查询指定bundleName的额外信息。该返回值是在调用install接口时传入的[InstallParam](./js-apis-installer.md#installparam)中的additionalInfo字段。 4252 4253**系统接口:** 此接口为系统接口。 4254 4255**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4256 4257**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4258 4259**参数:** 4260 4261| 参数名 | 类型 | 必填 | 说明 | 4262| -------------- | ----------------------------------- | ---- | ---------------------------- | 4263| bundleName | string | 是 | 指定的bundleName。 | 4264 4265**返回值:** 4266 4267| 类型 | 说明 | 4268| ------------- | -------------------------------------- | 4269| string | 返回指定bundleName的额外信息。 | 4270 4271**错误码:** 4272 4273以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 4274 4275| 错误码ID | 错误信息 | 4276| -------- | ------------------------------------------------------------ | 4277| 17700001 | The specified bundleName is not found. | 4278 4279**示例:** 4280 4281```ts 4282import bundleManager from '@ohos.bundle.bundleManager'; 4283import { BusinessError } from '@ohos.base'; 4284let bundleName = "com.example.myapplication"; 4285 4286try { 4287 let info = bundleManager.getAdditionalInfo(bundleName); 4288 console.info('getAdditionalInfo successfully, additionInfo:' + info); 4289} catch (error) { 4290 let message = (error as BusinessError).message; 4291 console.error('getAdditionalInfo failed. Cause: ' + message); 4292} 4293``` 4294 4295### bundleManager.getBundleInfoForSelfSync<sup>10+</sup> 4296 4297getBundleInfoForSelfSync(bundleFlags: number): BundleInfo; 4298 4299以同步方法根据给定的bundleFlags获取当前应用的BundleInfo。 4300 4301**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4302 4303**参数:** 4304 4305| 参数名 | 类型 | 必填 | 说明 | 4306| ----------- | ------ | ---- | --------------------- | 4307| bundleFlags | [number](#bundleflag) | 是 | 指定返回的BundleInfo所包含的信息。 | 4308 4309**返回值:** 4310 4311| 类型 | 说明 | 4312| ------------------------------------------------- | -------------------- | 4313| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 4314 4315**示例:** 4316 4317```ts 4318import bundleManager from '@ohos.bundle.bundleManager'; 4319import { BusinessError } from '@ohos.base'; 4320import hilog from '@ohos.hilog'; 4321let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 4322try { 4323 let data = bundleManager.getBundleInfoForSelfSync(bundleFlags); 4324 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelfSync successfully: %{public}s', JSON.stringify(data)); 4325} catch (err) { 4326 let message = (err as BusinessError).message; 4327 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelfSync failed: %{public}s', message); 4328} 4329```