1# @ohos.bundle.bundleManager (bundleManager模块)(系统接口) 2 3本模块提供应用信息查询能力,支持[BundleInfo](js-apis-bundleManager-bundleInfo.md)、[ApplicationInfo](js-apis-bundleManager-ApplicationInfo-sys.md)、[AbilityInfo](js-apis-bundleManager-abilityInfo.md)、[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)等信息的查询。 4 5> **说明:** 6> 7> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 当前页面仅包含本模块的系统接口,其他公开接口参见[`@ohos.bundle.bundleManager`](js-apis-bundleManager.md)。 10 11## 导入模块 12 13```ts 14import { bundleManager } from '@kit.AbilityKit'; 15``` 16 17## 权限列表 18 19| 权限 | 权限等级 | 描述 | 20| ------------------------------------------ | ------------ | ------------------| 21| ohos.permission.GET_BUNDLE_INFO | normal | 允许查询应用的基本信息。 | 22| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 允许查询应用的基本信息和其他敏感信息。 | 23| ohos.permission.REMOVE_CACHE_FILES | system_basic | 清理应用缓存。 | 24| ohos.permission.CHANGE_ABILITY_ENABLED_STATE| system_basic | 设置禁用使能所需的权限。 | 25| ohos.permission.GET_INSTALLED_BUNDLE_LIST | system_basic | 读取已安装应用列表。 | 26 27权限等级参考[权限APL等级说明](../../security/AccessToken/app-permission-mgmt-overview.md#权限机制中的基本概念)。 28 29## BundleFlag 30 31包信息标志,指示需要获取的包信息的内容。 32 33 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 34 35| 名称 | 值 | 说明 | 36| --------------------------------------------- | ---------- | ------------------------------------------------------------ | 37| GET_BUNDLE_INFO_DEFAULT | 0x00000000 | 用于获取默认bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 38| GET_BUNDLE_INFO_WITH_APPLICATION | 0x00000001 | 用于获取包含applicationInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 39| GET_BUNDLE_INFO_WITH_HAP_MODULE | 0x00000002 | 用于获取包含hapModuleInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability、extensionAbility和permission的信息。 | 40| GET_BUNDLE_INFO_WITH_ABILITY | 0x00000004 | 用于获取包含ability的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、extensionAbility和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 41| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY | 0x00000008 | 用于获取包含extensionAbility的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability 和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 42| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION | 0x00000010 | 用于获取包含permission的bundleInfo。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、extensionAbility和ability的信息。 | 43| 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一起使用。 | 44| GET_BUNDLE_INFO_WITH_DISABLE | 0x00000040 | 用于获取application被禁用的BundleInfo和被禁用的Ability信息。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 | 45| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO | 0x00000080 | 用于获取包含signatureInfo的bundleInfo。获取的bundleInfo不包含applicationInfo、hapModuleInfo、extensionAbility、ability和permission的信息。 | 46| GET_BUNDLE_INFO_WITH_MENU<sup>11+</sup> | 0x00000100 | 用于获取包含fileContextMenuConfig的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 47| GET_BUNDLE_INFO_WITH_ROUTER_MAP<sup>12+</sup> | 0x00000200 | 用于获取包含routerMap的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 | 48| GET_BUNDLE_INFO_WITH_SKILL<sup>12+</sup> | 0x00000800 | 用于获取包含skills的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE、GET_BUNDLE_INFO_WITH_ABILITY、GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY一起使用。 | 49| GET_BUNDLE_INFO_ONLY_WITH_LAUNCHER_ABILITY<sup>12+</sup> | 0x00001000 | 用于获取仅包含有桌面图标的应用的bundleInfo。它仅在[getAllBundleInfo](#bundlemanagergetallbundleinfo)接口中生效。 | 50| GET_BUNDLE_INFO_OF_ANY_USER<sup>12+</sup> | 0x00002000 | 用于获取任意用户安装的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_APPLICATION一起使用。它仅在[getBundleInfo](#bundlemanagergetbundleinfo14)、[getAllBundleInfo](#bundlemanagergetallbundleinfo)接口生效。<br/>**系统API:** 从API version 12开始,该接口支持在系统API中使用。 | 51| GET_BUNDLE_INFO_EXCLUDE_CLONE<sup>12+</sup> | 0x00004000 | 用于获取去除分身应用而仅包含主应用的bundleInfo。它仅在[getAllBundleInfo](#bundlemanagergetallbundleinfo)接口中生效。 | 52 53## ApplicationFlag 54 55应用信息标志,指示需要获取的应用信息的内容。 56 57 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 58 59 **系统接口:** 此接口为系统接口。 60 61| 名称 | 值 | 说明 | 62| ------------------------------------ | ---------- | ------------------------------------------------------------ | 63| GET_APPLICATION_INFO_DEFAULT | 0x00000000 | 用于获取默认的applicationInfo,获取的applicationInfo不包含permission和metadata信息。 | 64| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的applicationInfo。 | 65| GET_APPLICATION_INFO_WITH_METADATA | 0x00000002 | 用于获取包含metadata的applicationInfo。 | 66| GET_APPLICATION_INFO_WITH_DISABLE | 0x00000004 | 用于获取包含禁用应用程序的applicationInfo。 | 67 68## AbilityFlag 69 70Ability组件信息标志,指示需要获取的Ability组件信息的内容。 71 72 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 73 74 **系统接口:** 此接口为系统接口。 75 76| 名称 | 值 | 说明 | 77| --------------------------------- | ---------- | ------------------------------------------------------------ | 78| GET_ABILITY_INFO_DEFAULT | 0x00000000 | 用于获取默认abilityInfo,获取的abilityInfo不包含permission、metadata和禁用的abilityInfo。 | 79| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的abilityInfo。 | 80| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的abilityInfo。 | 81| GET_ABILITY_INFO_WITH_METADATA | 0x00000004 | 用于获取包含metadata的abilityInfo。 | 82| GET_ABILITY_INFO_WITH_DISABLE | 0x00000008 | 用于获取包含禁用的abilityInfo的abilityInfo。 | 83| GET_ABILITY_INFO_ONLY_SYSTEM_APP | 0x00000010 | 用于仅为系统应用程序获取abilityInfo。 | 84| GET_ABILITY_INFO_WITH_APP_LINKING<sup>12+</sup> | 0x00000040 | 用于获取通过域名校验筛选的abilityInfo。 | 85| GET_ABILITY_INFO_WITH_SKILL<sup>12+</sup> | 0x00000080 | 用于获取包含skills的abilityInfo。 | 86 87## ExtensionAbilityFlag 88 89扩展组件信息标志,指示需要获取的扩展组件信息的内容。 90 91 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 92 93 **系统接口:** 此接口为系统接口。 94 95| 名称 | 值 | 说明 | 96| ------------------------------------------- | ---------- | ------------------------------------------------------------ | 97| GET_EXTENSION_ABILITY_INFO_DEFAULT | 0x00000000 | 用于获取默认extensionAbilityInfo。获取的extensionAbilityInfo不包含permission、metadata 和禁用的abilityInfo。 | 98| GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的extensionAbilityInfo。 | 99| GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的extensionAbilityInfo。 | 100| GET_EXTENSION_ABILITY_INFO_WITH_METADATA | 0x00000004 | 用于获取包含metadata的extensionAbilityInfo。 | 101| GET_EXTENSION_ABILITY_INFO_WITH_SKILL<sup>12+</sup> | 0x00000010 | 用于获取包含skills的extensionAbilityInfo。 | 102 103## ProfileType<sup>11+</sup> 104 105标识配置文件类型。 106 107 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 108 109 **系统接口:** 此接口为系统接口。 110 111| 名称 | 值 | 说明 | 112| -------------- | ---- | --------------- | 113| INTENT_PROFILE | 1 | 意图框架配置文件。 | 114 115## AppDistributionType<sup>12+</sup> 116 117标识应用[分发类型](../../security/app-provision-structure.md)。 118 119 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 120 121 **系统接口:** 此接口为系统接口。 122 123| 名称 | 值 | 说明 | 124| ----------------- | ---- | --------------- | 125| APP_GALLERY | 1 | 应用市场分发的应用。 | 126| ENTERPRISE | 2 | 企业应用,可以安装到个人设备上。 | 127| ENTERPRISE_NORMAL | 3 | 普通企业应用,只能通过企业MDM应用安装在企业设备上。无需设备管理特权。 | 128| ENTERPRISE_MDM | 4 | 企业MDM应用,只能安装在企业设备上。需要设备管理特权,比如远程锁定,安装普通企业应用等。 | 129| OS_INTEGRATION | 5 | 系统预置应用。 | 130| CROWDTESTING | 6 | 众包测试应用。 | 131| NONE | 7 | 其他。 | 132 133## ApplicationInfoFlag<sup>12+</sup> 134标识应用和用户之间的各种状态类型。 135 136 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 137 138 **系统接口:** 此接口为系统接口。 139 140| 名称 | 值 | 说明 | 141|----------------|---|---| 142| FLAG_INSTALLED| 0x00000001 | 表示指定用户安装应用的状态为已安装状态。 | 143| FLAG_OTHER_INSTALLED<sup>15+</sup>| 0x00000010 | 表示除指定用户外,其他用户的应用安装状态为已安装。| 144| FLAG_PREINSTALLED_APP<sup>15+</sup>| 0x00000020 | 表示应用的预置属性为预置应用。| 145| FLAG_PREINSTALLED_APP_UPDATE<sup>15+</sup>| 0x00000040 | 表示该预置应用的更新状态为已更新。| 146 147## bundleManager.getBundleInfo<sup>14+</sup> 148 149getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void 150 151根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用callback异步回调。 152 153获取调用方自己的信息时不需要权限。 154 155**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 156 157**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 158 159**参数:** 160 161| 参数名 | 类型 | 必填 | 说明 | 162| ----------- | ------ | ---- | ---------------------------- | 163| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 164| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 指定返回的BundleInfo所包含的信息。| 165| userId | number | 是 | 表示用户ID。 | 166| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的bundleInfo;否则为错误对象。 | 167 168**错误码:** 169 170以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 171 172| 错误码ID | 错误信息 | 173| -------- | ------------------------------------- | 174| 201 | Permission denied. | 175| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 176| 17700001 | The specified bundleName is not found. | 177| 17700004 | The specified user ID is not found. | 178| 17700026 | The specified bundle is disabled. | 179 180**示例:** 181 182```ts 183// 额外获取AbilityInfo 184import { bundleManager } from '@kit.AbilityKit'; 185import { BusinessError } from '@kit.BasicServicesKit'; 186import { hilog } from '@kit.PerformanceAnalysisKit'; 187let bundleName = 'com.example.myapplication'; 188let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY; 189let userId = 100; 190 191try { 192 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 193 if (err) { 194 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 195 } else { 196 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 197 } 198 }); 199} catch (err) { 200 let message = (err as BusinessError).message; 201 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 202} 203``` 204 205```ts 206// 额外获取ApplicationInfo中的metadata 207import { bundleManager } from '@kit.AbilityKit'; 208import { BusinessError } from '@kit.BasicServicesKit'; 209import { hilog } from '@kit.PerformanceAnalysisKit'; 210let bundleName = 'com.example.myapplication'; 211let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; 212let userId = 100; 213 214try { 215 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 216 if (err) { 217 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 218 } else { 219 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 220 } 221 }); 222} catch (err) { 223 let message = (err as BusinessError).message; 224 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 225} 226``` 227 228## bundleManager.getBundleInfo<sup>14+</sup> 229 230getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void 231 232根据给定的bundleName和bundleFlags获取BundleInfo,使用callback异步回调。 233 234获取调用方自己的信息时不需要权限。 235 236**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 237 238**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 239 240**参数:** 241 242| 参数名 | 类型 | 必填 | 说明 | 243| ----------- | ------ | ---- | ---------------------------- | 244| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 245| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 指定返回的BundleInfo所包含的信息。| 246| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | 247 248**错误码:** 249 250以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 251 252| 错误码ID | 错误信息 | 253| -------- | ------------------------------------- | 254| 201 | Permission denied. | 255| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 256| 17700001 | The specified bundleName is not found. | 257| 17700026 | The specified bundle is disabled. | 258 259**示例:** 260 261```ts 262// 额外获取extensionAbility 263import { bundleManager } from '@kit.AbilityKit'; 264import { BusinessError } from '@kit.BasicServicesKit'; 265import { hilog } from '@kit.PerformanceAnalysisKit'; 266let bundleName = 'com.example.myapplication'; 267let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; 268 269try { 270 bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => { 271 if (err) { 272 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 273 } else { 274 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 275 } 276 }); 277} catch (err) { 278 let message = (err as BusinessError).message; 279 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 280} 281``` 282 283## bundleManager.getBundleInfo<sup>14+</sup> 284 285getBundleInfo(bundleName: string, bundleFlags: number, userId?: number): Promise\<BundleInfo> 286 287根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用Promise异步回调。 288 289获取调用方自己的信息时不需要权限。 290 291**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 292 293**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 294 295**参数:** 296 297| 参数名 | 类型 | 必填 | 说明 | 298| ----------- | ------ | ---- | ---------------------------- | 299| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 300| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 指定返回的BundleInfo所包含的信息。 | 301| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 302 303**返回值:** 304 305| 类型 | 说明 | 306| ----------------------------------------------------------- | --------------------------- | 307| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 | 308 309**错误码:** 310 311以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 312 313| 错误码ID | 错误信息 | 314| -------- | --------------------------------------| 315| 201 | Permission denied. | 316| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 317| 17700001 | The specified bundleName is not found. | 318| 17700004 | The specified user ID is not found. | 319| 17700026 | The specified bundle is disabled. | 320 321**示例:** 322 323```ts 324// 额外获取ApplicationInfo和SignatureInfo 325import { bundleManager } from '@kit.AbilityKit'; 326import { BusinessError } from '@kit.BasicServicesKit'; 327import { hilog } from '@kit.PerformanceAnalysisKit'; 328let bundleName = 'com.example.myapplication'; 329let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; 330let userId = 100; 331 332try { 333 bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => { 334 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 335 }).catch((err: BusinessError) => { 336 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 337 }); 338} catch (err) { 339 let message = (err as BusinessError).message; 340 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message); 341} 342``` 343 344```ts 345import { bundleManager } from '@kit.AbilityKit'; 346import { BusinessError } from '@kit.BasicServicesKit'; 347import { hilog } from '@kit.PerformanceAnalysisKit'; 348let bundleName = 'com.example.myapplication'; 349let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 350 351try { 352 bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => { 353 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 354 }).catch((err: BusinessError) => { 355 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 356 }); 357} catch (err) { 358 let message = (err as BusinessError).message; 359 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message); 360} 361 362``` 363 364## bundleManager.getApplicationInfo 365 366getApplicationInfo(bundleName: string, appFlags: number, userId: number, callback: AsyncCallback\<ApplicationInfo>): void 367 368根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用callback异步回调。 369 370获取调用方自己的信息时不需要权限。 371 372**系统接口:** 此接口为系统接口。 373 374**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 375 376**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 377 378**参数:** 379 380| 参数名 | 类型 | 必填 | 说明 | 381| ---------- | ------ | ---- | ---------------------------- | 382| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 383| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 384| userId | number | 是 | 表示用户ID。 | 385| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | 386 387**错误码:** 388 389以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 390 391| 错误码ID | 错误信息 | 392| -------- | --------------------------------------| 393| 201 | Permission denied. | 394| 202 | Permission denied, non-system app called system api. | 395| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 396| 17700001 | The specified bundleName is not found. | 397| 17700004 | The specified user ID is not found. | 398| 17700026 | The specified bundle is disabled. | 399 400**示例:** 401 402```ts 403import { bundleManager } from '@kit.AbilityKit'; 404import { BusinessError } from '@kit.BasicServicesKit'; 405import { hilog } from '@kit.PerformanceAnalysisKit'; 406let bundleName = 'com.example.myapplication'; 407let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 408let userId = 100; 409 410try { 411 bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => { 412 if (err) { 413 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 414 } else { 415 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 416 } 417 }); 418} catch (err) { 419 let message = (err as BusinessError).message; 420 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message); 421} 422``` 423 424## bundleManager.getApplicationInfo 425 426getApplicationInfo(bundleName: string, appFlags: number, callback: AsyncCallback\<ApplicationInfo>): void 427 428根据给定的bundleName和appFlags获取ApplicationInfo,使用callback异步回调。 429 430获取调用方自己的信息时不需要权限。 431 432**系统接口:** 此接口为系统接口。 433 434**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 435 436**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 437 438**参数:** 439 440| 参数名 | 类型 | 必填 | 说明 | 441| ---------- | ------ | ---- | ---------------------------- | 442| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 443| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 444| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 | 445 446**错误码:** 447 448以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 449 450| 错误码ID | 错误信息 | 451| -------- | --------------------------------------| 452| 201 | Permission denied. | 453| 202 | Permission denied, non-system app called system api. | 454| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 455| 17700001 | The specified bundleName is not found. | 456| 17700026 | The specified bundle is disabled. | 457 458**示例:** 459 460```ts 461import { bundleManager } from '@kit.AbilityKit'; 462import { BusinessError } from '@kit.BasicServicesKit'; 463import { hilog } from '@kit.PerformanceAnalysisKit'; 464let bundleName = 'com.example.myapplication'; 465let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 466 467try { 468 bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => { 469 if (err) { 470 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 471 } else { 472 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 473 } 474 }); 475} catch (err) { 476 let message = (err as BusinessError).message; 477 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message); 478} 479``` 480 481## bundleManager.getApplicationInfo 482 483getApplicationInfo(bundleName: string, appFlags: number, userId?: number): Promise\<ApplicationInfo> 484 485根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用Promise异步回调。 486 487获取调用方自己的信息时不需要权限。 488 489**系统接口:** 此接口为系统接口。 490 491**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 492 493**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 494 495**参数:** 496 497| 参数名 | 类型 | 必填 | 说明 | 498| ---------- | ------ | ---- | ---------------------------- | 499| bundleName | string | 是 | 表示要查询的应用Bundle名称。 | 500| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 501| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 502 503**返回值:** 504 505| 类型 | 说明 | 506| ------------------------------------------------------------ | -------------------------------- | 507| Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Promise对象,返回ApplicationInfo。 | 508 509**错误码:** 510 511以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 512 513| 错误码ID | 错误信息 | 514| -------- | ------------------------------------- | 515| 201 | Permission denied. | 516| 202 | Permission denied, non-system app called system api. | 517| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 518| 17700001 | The specified bundleName is not found. | 519| 17700004 | The specified user ID is not found. | 520| 17700026 | The specified bundle is disabled. | 521 522**示例:** 523 524```ts 525import { bundleManager } from '@kit.AbilityKit'; 526import { BusinessError } from '@kit.BasicServicesKit'; 527import { hilog } from '@kit.PerformanceAnalysisKit'; 528let bundleName = 'com.example.myapplication'; 529let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 530let userId = 100; 531 532try { 533 bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => { 534 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 535 }).catch((err: BusinessError) => { 536 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message); 537 }); 538} catch (err) { 539 let message = (err as BusinessError).message; 540 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', message); 541} 542``` 543 544## bundleManager.getAllBundleInfo 545 546getAllBundleInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array\<BundleInfo>>): void 547 548根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback异步回调。 549 550**系统接口:** 此接口为系统接口。 551 552**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 553 554**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 555 556**参数:** 557 558| 参数名 | 类型 | 必填 | 说明 | 559| ----------- | ------ | ---- | -------------------------------------------------- | 560| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 指定返回的BundleInfo所包含的信息。 | 561| userId | number | 是 | 表示用户ID。 | 562| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 | 563 564**错误码:** 565 566以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 567 568| 错误码ID | 错误信息 | 569| -------- | --------------------------------- | 570| 201 | Permission denied. | 571| 202 | Permission denied, non-system app called system api. | 572| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 573| 17700004 | The specified user ID is not found. | 574 575**示例:** 576 577```ts 578import { bundleManager } from '@kit.AbilityKit'; 579import { BusinessError } from '@kit.BasicServicesKit'; 580import { hilog } from '@kit.PerformanceAnalysisKit'; 581let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 582let userId = 100; 583 584try { 585 bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => { 586 if (err) { 587 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 588 } else { 589 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 590 } 591 }); 592} catch (err) { 593 let message = (err as BusinessError).message; 594 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message); 595} 596``` 597 598## bundleManager.getAllBundleInfo 599 600getAllBundleInfo(bundleFlags: number, callback: AsyncCallback<Array\<BundleInfo>>): void 601 602根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback异步回调。 603 604**系统接口:** 此接口为系统接口。 605 606**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 607 608**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 609 610**参数:** 611 612| 参数名 | 类型 | 必填 | 说明 | 613| ----------- | ------ | ---- | -------------------------------------------------- | 614| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 指定返回的BundleInfo所包含的信息。 | 615| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 | 616 617**错误码:** 618 619以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 620 621| 错误码ID | 错误信息 | 622| -------- | ---------------------------------- | 623| 201 | Permission denied. | 624| 202 | Permission denied, non-system app called system api. | 625| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 626 627**示例:** 628 629```ts 630import { bundleManager } from '@kit.AbilityKit'; 631import { BusinessError } from '@kit.BasicServicesKit'; 632import { hilog } from '@kit.PerformanceAnalysisKit'; 633let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 634 635try { 636 bundleManager.getAllBundleInfo(bundleFlags, (err, data) => { 637 if (err) { 638 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 639 } else { 640 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 641 } 642 }); 643} catch (err) { 644 let message = (err as BusinessError).message; 645 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message); 646} 647``` 648 649## bundleManager.getAllBundleInfo 650 651getAllBundleInfo(bundleFlags: number, userId?: number): Promise<Array\<BundleInfo>> 652 653根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise异步回调。 654 655**系统接口:** 此接口为系统接口。 656 657**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 658 659**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 660 661**参数:** 662 663| 参数名 | 类型 | 必填 | 说明 | 664| ----------- | ------ | ---- | -------------------------------------------------- | 665| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 指定返回的BundleInfo所包含的信息。 | 666| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 667 668**返回值:** 669 670| 类型 | 说明 | 671| ------------------------------------------------------------ | ----------------------------------- | 672| Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Promise对象,返回Array\<BundleInfo>。 | 673 674**错误码:** 675 676以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 677 678| 错误码ID | 错误信息 | 679| -------- | ---------------------------------- | 680| 201 | Permission denied. | 681| 202 | Permission denied, non-system app called system api. | 682| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 683| 17700004 | The specified user ID is not found. | 684 685**示例:** 686 687```ts 688import { bundleManager } from '@kit.AbilityKit'; 689import { BusinessError } from '@kit.BasicServicesKit'; 690import { hilog } from '@kit.PerformanceAnalysisKit'; 691let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 692 693try { 694 bundleManager.getAllBundleInfo(bundleFlags).then((data) => { 695 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 696 }).catch((err: BusinessError) => { 697 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message); 698 }); 699} catch (err) { 700 let message = (err as BusinessError).message; 701 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', message); 702} 703``` 704 705## bundleManager.getAllApplicationInfo 706 707getAllApplicationInfo(appFlags: number, userId: number, callback: AsyncCallback<Array\<ApplicationInfo>>): void 708 709根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback异步回调。 710 711**系统接口:** 此接口为系统接口。 712 713**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 714 715**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 716 717**参数:** 718 719| 参数名 | 类型 | 必填 | 说明 | 720| -------- | ------ | ---- | ----------------------------------------------------------- | 721| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 722| userId | number | 是 | 表示用户ID。 | 723| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 | 724 725**错误码:** 726 727以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 728 729| 错误码ID | 错误信息 | 730| -------- | ---------------------------------- | 731| 201 | Permission denied. | 732| 202 | Permission denied, non-system app called system api. | 733| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 734| 17700004 | The specified user ID is not found. | 735 736**示例:** 737 738```ts 739import { bundleManager } from '@kit.AbilityKit'; 740import { BusinessError } from '@kit.BasicServicesKit'; 741import { hilog } from '@kit.PerformanceAnalysisKit'; 742let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 743let userId = 100; 744 745try { 746 bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => { 747 if (err) { 748 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 749 } else { 750 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 751 } 752 }); 753} catch (err) { 754 let message = (err as BusinessError).message; 755 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message); 756} 757``` 758 759## bundleManager.getAllApplicationInfo 760 761getAllApplicationInfo(appFlags: number, callback: AsyncCallback<Array\<ApplicationInfo>>): void 762 763根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback异步回调。 764 765**系统接口:** 此接口为系统接口。 766 767**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 768 769**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 770 771**参数:** 772 773| 参数名 | 类型 | 必填 | 说明 | 774| -------- | ------ | ---- | ----------------------------------------------------------- | 775| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 776| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 | 777 778**错误码:** 779 780以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 781 782| 错误码ID | 错误信息 | 783| -------- | ---------------------------------- | 784| 201 | Permission denied. | 785| 202 | Permission denied, non-system app called system api. | 786| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 787 788**示例:** 789 790```ts 791import { bundleManager } from '@kit.AbilityKit'; 792import { BusinessError } from '@kit.BasicServicesKit'; 793import { hilog } from '@kit.PerformanceAnalysisKit'; 794let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 795 796try { 797 bundleManager.getAllApplicationInfo(appFlags, (err, data) => { 798 if (err) { 799 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 800 } else { 801 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 802 } 803 }); 804} catch (err) { 805 let message = (err as BusinessError).message; 806 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message); 807} 808``` 809 810## bundleManager.getAllApplicationInfo 811 812getAllApplicationInfo(appFlags: number, userId?: number): Promise<Array\<ApplicationInfo>> 813 814根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise异步回调。 815 816**系统接口:** 此接口为系统接口。 817 818**需要权限:** ohos.permission.GET_INSTALLED_BUNDLE_LIST 819 820**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 821 822**参数:** 823 824| 参数名 | 类型 | 必填 | 说明 | 825| -------- | ------ | ---- | ---------------------------------------------------------- | 826| appFlags | [number](#applicationflag) | 是 | 指定返回的ApplicationInfo所包含的信息。 | 827| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 828 829**返回值:** 830 831| 类型 | 说明 | 832| ------------------------------------------------------------ | ---------------------------------------- | 833| Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Promise对象,返回Array\<ApplicationInfo>。 | 834 835**错误码:** 836 837以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 838 839| 错误码ID | 错误信息 | 840| -------- | ---------------------------------- | 841| 201 | Permission denied. | 842| 202 | Permission denied, non-system app called system api. | 843| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 844| 17700004 | The specified user ID is not found. | 845 846**示例:** 847 848```ts 849import { bundleManager } from '@kit.AbilityKit'; 850import { BusinessError } from '@kit.BasicServicesKit'; 851import { hilog } from '@kit.PerformanceAnalysisKit'; 852let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 853 854try { 855 bundleManager.getAllApplicationInfo(appFlags).then((data) => { 856 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 857 }).catch((err: BusinessError) => { 858 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message); 859 }); 860} catch (err) { 861 let message = (err as BusinessError).message; 862 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', message); 863} 864 865``` 866 867## bundleManager.queryAbilityInfo 868 869queryAbilityInfo(want: Want, abilityFlags: number, userId: number, callback: AsyncCallback<Array\<AbilityInfo>>): void 870 871根据给定的want、abilityFlags和userId获取多个AbilityInfo,使用callback异步回调。 872 873**系统接口:** 此接口为系统接口。 874 875**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 876 877**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 878 879**参数:** 880 881| 参数名 | 类型 | 必填 | 说明 | 882| ------------ | ------ | ---- | ------------------------------------------------------- | 883| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 884| abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | 885| userId | number | 是 | 表示用户ID。 | 886| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 | 887 888**错误码:** 889 890以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 891 892| 错误码ID | 错误信息 | 893| -------- | -------------------------------------- | 894| 201 | Permission denied. | 895| 202 | Permission denied, non-system app called system api. | 896| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 897| 17700001 | The specified bundleName is not found. | 898| 17700003 | The specified ability is not found. | 899| 17700004 | The specified userId is invalid. | 900| 17700026 | The specified bundle is disabled. | 901| 17700029 | The specified ability is disabled. | 902 903**示例:** 904 905```ts 906import { bundleManager } from '@kit.AbilityKit'; 907import { BusinessError } from '@kit.BasicServicesKit'; 908import { hilog } from '@kit.PerformanceAnalysisKit'; 909import { Want } from '@kit.AbilityKit'; 910let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 911let userId = 100; 912let want: Want = { 913 bundleName : "com.example.myapplication", 914 abilityName : "EntryAbility" 915}; 916 917try { 918 bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => { 919 if (err) { 920 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 921 } else { 922 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 923 } 924 }); 925} catch (err) { 926 let message = (err as BusinessError).message; 927 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message); 928} 929``` 930 931## bundleManager.queryAbilityInfo 932 933queryAbilityInfo(want: Want, abilityFlags: number, callback: AsyncCallback<Array\<AbilityInfo>>): void 934 935根据给定的want和abilityFlags获取一个或多个AbilityInfo,使用callback异步回调。 936 937**系统接口:** 此接口为系统接口。 938 939**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 940 941**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 942 943**参数:** 944 945| 参数名 | 类型 | 必填 | 说明 | 946| ------------ | ------ | ---- | -------------------------------------------------------| 947| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 948| abilityFlags | [number](#abilityflag) | 是 | 指定返回的AbilityInfo所包含的信息。 | 949| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 | 950 951**错误码:** 952 953以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 954 955| 错误码ID | 错误信息 | 956| -------- | -------------------------------------- | 957| 201 | Permission denied. | 958| 202 | Permission denied, non-system app called system api. | 959| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 960| 17700001 | The specified bundleName is not found. | 961| 17700003 | The specified ability is not found. | 962| 17700026 | The specified bundle is disabled. | 963| 17700029 | The specified ability is disabled. | 964 965**示例:** 966 967```ts 968import { bundleManager } from '@kit.AbilityKit'; 969import { BusinessError } from '@kit.BasicServicesKit'; 970import { hilog } from '@kit.PerformanceAnalysisKit'; 971import { Want } from '@kit.AbilityKit'; 972let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 973let want: Want = { 974 bundleName : "com.example.myapplication", 975 abilityName : "EntryAbility" 976}; 977 978try { 979 bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => { 980 if (err) { 981 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 982 } else { 983 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 984 } 985 }); 986} catch (err) { 987 let message = (err as BusinessError).message; 988 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message); 989} 990``` 991 992## bundleManager.queryAbilityInfo 993 994queryAbilityInfo(want: Want, abilityFlags: number, userId?: number): Promise<Array\<AbilityInfo>> 995 996根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo,使用Promise异步回调。 997 998**系统接口:** 此接口为系统接口。 999 1000**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1001 1002**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1003 1004**参数:** 1005 1006| 参数名 | 类型 | 必填 | 说明 | 1007| ------------ | ------ | ---- | ------------------------------------------------------- | 1008| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1009| abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | 1010| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1011 1012**返回值:** 1013 1014| 类型 | 说明 | 1015| ------------------------------------------------------------ | ------------------------------------ | 1016| Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Promise对象,返回Array\<AbilityInfo>。 | 1017 1018**错误码:** 1019 1020以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1021 1022| 错误码ID | 错误信息 | 1023| -------- | ------------------------------------- | 1024| 201 | Permission denied. | 1025| 202 | Permission denied, non-system app called system api. | 1026| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1027| 17700001 | The specified bundleName is not found. | 1028| 17700003 | The specified ability is not found. | 1029| 17700004 | The specified userId is invalid. | 1030| 17700026 | The specified bundle is disabled. | 1031| 17700029 | The specified ability is disabled. | 1032 1033**示例:** 1034 1035```ts 1036import { bundleManager } from '@kit.AbilityKit'; 1037import { BusinessError } from '@kit.BasicServicesKit'; 1038import { hilog } from '@kit.PerformanceAnalysisKit'; 1039import { Want } from '@kit.AbilityKit'; 1040let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1041let userId = 100; 1042let want: Want = { 1043 bundleName : "com.example.myapplication", 1044 abilityName : "EntryAbility" 1045}; 1046 1047try { 1048 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => { 1049 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1050 }).catch((err: BusinessError) => { 1051 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1052 }); 1053} catch (err) { 1054 let message = (err as BusinessError).message; 1055 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1056} 1057``` 1058 1059```ts 1060import { bundleManager } from '@kit.AbilityKit'; 1061import { BusinessError } from '@kit.BasicServicesKit'; 1062import { hilog } from '@kit.PerformanceAnalysisKit'; 1063import { Want } from '@kit.AbilityKit'; 1064let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1065let want: Want = { 1066 bundleName : "com.example.myapplication", 1067 abilityName : "EntryAbility" 1068}; 1069 1070try { 1071 bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => { 1072 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1073 }).catch((err: BusinessError) => { 1074 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1075 }) 1076} catch (err) { 1077 let message = (err as BusinessError).message; 1078 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1079} 1080``` 1081 1082## bundleManager.queryAbilityInfoSync<sup>10+</sup> 1083 1084queryAbilityInfoSync(want: Want, abilityFlags: number, userId?: number): Array\<AbilityInfo> 1085 1086以同步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo。 1087 1088**系统接口:** 此接口为系统接口。 1089 1090**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1091 1092**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1093 1094**参数:** 1095 1096| 参数名 | 类型 | 必填 | 说明 | 1097| ------------ | ------ | ---- | ------------------------------------------------------- | 1098| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1099| abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | 1100| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1101 1102**返回值:** 1103 1104| 类型 | 说明 | 1105| ------------------------------------------------------------ | ------------------------------------ | 1106| Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | Array\<AbilityInfo>信息。 | 1107 1108**错误码:** 1109 1110以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1111 1112| 错误码ID | 错误信息 | 1113| -------- | ------------------------------------- | 1114| 201 | Permission denied. | 1115| 202 | Permission denied, non-system app called system api. | 1116| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1117| 17700001 | The specified bundleName is not found. | 1118| 17700003 | The specified ability is not found. | 1119| 17700004 | The specified userId is invalid. | 1120| 17700026 | The specified bundle is disabled. | 1121| 17700029 | The specified ability is disabled. | 1122 1123**示例:** 1124 1125```ts 1126import { bundleManager } from '@kit.AbilityKit'; 1127import { BusinessError } from '@kit.BasicServicesKit'; 1128import { hilog } from '@kit.PerformanceAnalysisKit'; 1129import { Want } from '@kit.AbilityKit'; 1130let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1131let userId = 100; 1132let want: Want = { 1133 bundleName : "com.example.myapplication", 1134 abilityName : "EntryAbility" 1135}; 1136 1137try { 1138 1139 let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags, userId); 1140 hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos)); 1141} catch (err) { 1142 let message = (err as BusinessError).message; 1143 hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message); 1144} 1145``` 1146 1147```ts 1148import { bundleManager } from '@kit.AbilityKit'; 1149import { BusinessError } from '@kit.BasicServicesKit'; 1150import { hilog } from '@kit.PerformanceAnalysisKit'; 1151import { Want } from '@kit.AbilityKit'; 1152let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1153let want: Want = { 1154 bundleName : "com.example.myapplication", 1155 abilityName : "EntryAbility" 1156}; 1157 1158try { 1159 let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags); 1160 hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos)); 1161} catch (err) { 1162 let message = (err as BusinessError).message; 1163 hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message); 1164} 1165``` 1166 1167## bundleManager.queryAbilityInfo<sup>12+</sup> 1168 1169queryAbilityInfo(wants: Array\<Want>, abilityFlags: number, userId?: number): Promise<Array\<AbilityInfo>> 1170 1171根据给定的want列表、abilityFlags和userId获取一个或多个AbilityInfo,使用Promise异步回调。 1172 1173**系统接口:** 此接口为系统接口。 1174 1175**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1176 1177**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1178 1179**参数:** 1180 1181| 参数名 | 类型 | 必填 | 说明 | 1182| ------------ | ------ | ---- | ------------------------------------------------------- | 1183| want | Array\<Want> | 是 | 表示包含要查询的应用Bundle名称的Want集合。 | 1184| abilityFlags | [number](#abilityflag) | 是 | 表示指定返回的AbilityInfo所包含的信息。 | 1185| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1186 1187**返回值:** 1188 1189| 类型 | 说明 | 1190| ------------------------------------------------------------ | ------------------------------------ | 1191| Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | Array\<AbilityInfo>信息。 | 1192 1193**错误码:** 1194 1195以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1196 1197| 错误码ID | 错误信息 | 1198| -------- | ------------------------------------- | 1199| 201 | Permission denied. | 1200| 202 | Permission denied, non-system app called system api. | 1201| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1202| 17700001 | The specified bundleName is not found. | 1203| 17700003 | The specified ability is not found. | 1204| 17700004 | The specified userId is invalid. | 1205| 17700026 | The specified bundle is disabled. | 1206| 17700029 | The specified ability is disabled. | 1207 1208**示例:** 1209 1210```ts 1211import { bundleManager } from '@kit.AbilityKit'; 1212import { BusinessError } from '@kit.BasicServicesKit'; 1213import { hilog } from '@kit.PerformanceAnalysisKit'; 1214import { Want } from '@kit.AbilityKit'; 1215let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1216let userId = 100; 1217let want: Want = { 1218 bundleName : "com.example.myapplication1", 1219 abilityName : "EntryAbility" 1220}; 1221let want1: Want = { 1222 bundleName : "com.example.myapplication2", 1223 abilityName : "EntryAbility" 1224}; 1225let wants: Array<Want> = [ want, want1 ]; 1226 try { 1227 bundleManager.queryAbilityInfo(wants, abilityFlags, userId).then((data) => { 1228 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1229 }).catch((err: BusinessError) => { 1230 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1231 }) 1232 } catch (err) { 1233 let message = (err as BusinessError).message; 1234 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1235 } 1236``` 1237 1238## bundleManager.queryExtensionAbilityInfo 1239 1240queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, userId: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void 1241 1242根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取一个或多个ExtensionAbilityInfo,使用callback异步回调。 1243 1244**系统接口:** 此接口为系统接口。 1245 1246**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1247 1248**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1249 1250**参数:** 1251 1252| 参数名 | 类型 | 必填 | 说明 | 1253| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1254| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1255| extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager-sys.md#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1256| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1257| userId | number | 是 | 表示用户ID。 | 1258| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 | 1259 1260**错误码:** 1261 1262以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1263 1264| 错误码ID | 错误信息 | 1265| -------- | ------------------------------------------- | 1266| 201 | Permission denied. | 1267| 202 | Permission denied, non-system app called system api. | 1268| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1269| 17700001 | The specified bundleName is not found. | 1270| 17700003 | The specified extensionAbility is not found. | 1271| 17700004 | The specified userId is invalid. | 1272| 17700026 | The specified bundle is disabled. | 1273 1274**示例:** 1275 1276```ts 1277import { bundleManager } from '@kit.AbilityKit'; 1278import { BusinessError } from '@kit.BasicServicesKit'; 1279import { hilog } from '@kit.PerformanceAnalysisKit'; 1280import { Want } from '@kit.AbilityKit'; 1281let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1282let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1283let userId = 100; 1284let want: Want = { 1285 bundleName : "com.example.myapplication", 1286 abilityName : "EntryAbility" 1287}; 1288 1289try { 1290 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => { 1291 if (err) { 1292 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1293 } else { 1294 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1295 } 1296 }); 1297} catch (err) { 1298 let message = (err as BusinessError).message; 1299 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message); 1300} 1301``` 1302 1303## bundleManager.queryExtensionAbilityInfo 1304 1305queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void 1306 1307根据给定的want、extensionAbilityType和extensionAbilityFlags获取一个或多个ExtensionAbilityInfo,使用callback异步回调。 1308 1309**系统接口:** 此接口为系统接口。 1310 1311**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1312 1313**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1314 1315**参数:** 1316 1317| 参数名 | 类型 | 必填 | 说明 | 1318| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1319| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1320| extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager-sys.md#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1321| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1322| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 | 1323 1324**错误码:** 1325 1326以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1327 1328| 错误码ID | 错误信息 | 1329| -------- | -------------------------------------------- | 1330| 201 | Permission denied. | 1331| 202 | Permission denied, non-system app called system api. | 1332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1333| 17700001 | The specified bundleName is not found. | 1334| 17700003 | The specified extensionAbility is not found. | 1335| 17700026 | The specified bundle is disabled. | 1336 1337**示例:** 1338 1339```ts 1340import { bundleManager } from '@kit.AbilityKit'; 1341import { BusinessError } from '@kit.BasicServicesKit'; 1342import { hilog } from '@kit.PerformanceAnalysisKit'; 1343import { Want } from '@kit.AbilityKit'; 1344let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1345let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1346let want: Want = { 1347 bundleName : "com.example.myapplication", 1348 abilityName : "EntryAbility" 1349}; 1350 1351try { 1352 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => { 1353 if (err) { 1354 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1355 } else { 1356 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1357 } 1358 }); 1359} catch (err) { 1360 let message = (err as BusinessError).message; 1361 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message); 1362} 1363``` 1364 1365## bundleManager.queryExtensionAbilityInfo 1366 1367queryExtensionAbilityInfo(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, userId?: number): Promise<Array\<ExtensionAbilityInfo>> 1368 1369根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo,使用Promise异步回调。 1370 1371**系统接口:** 此接口为系统接口。 1372 1373**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1374 1375**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1376 1377**参数:** 1378 1379| 参数名 | 类型 | 必填 | 说明 | 1380| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1381| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1382| extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager-sys.md#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1383| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1384| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1385 1386**返回值:** 1387 1388| 类型 | 说明 | 1389| ------------------------------------------------------------ | --------------------------------------------- | 1390| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Promise对象,返回Array\<ExtensionAbilityInfo>。 | 1391 1392**错误码:** 1393 1394以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1395 1396| 错误码ID | 错误信息 | 1397| -------- | --------------------------------------| 1398| 201 | Permission denied. | 1399| 202 | Permission denied, non-system app called system api. | 1400| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1401| 17700001 | The specified bundleName is not found. | 1402| 17700003 | The specified extensionAbility is not found. | 1403| 17700004 | The specified userId is invalid. | 1404| 17700026 | The specified bundle is disabled. | 1405 1406**示例:** 1407 1408```ts 1409import { bundleManager } from '@kit.AbilityKit'; 1410import { BusinessError } from '@kit.BasicServicesKit'; 1411import { hilog } from '@kit.PerformanceAnalysisKit'; 1412import { Want } from '@kit.AbilityKit'; 1413 1414let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1415let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1416let userId = 100; 1417let want: Want = { 1418 bundleName : "com.example.myapplication", 1419 abilityName : "EntryAbility" 1420}; 1421 1422try { 1423 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => { 1424 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1425 }).catch((err: BusinessError) => { 1426 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1427 }); 1428} catch (err) { 1429 let message = (err as BusinessError).message; 1430 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message); 1431} 1432``` 1433 1434```ts 1435import { bundleManager } from '@kit.AbilityKit'; 1436import { BusinessError } from '@kit.BasicServicesKit'; 1437import { hilog } from '@kit.PerformanceAnalysisKit'; 1438import { Want } from '@kit.AbilityKit'; 1439let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1440let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1441let want: Want = { 1442 bundleName : "com.example.myapplication", 1443 abilityName : "EntryAbility" 1444}; 1445 1446try { 1447 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => { 1448 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1449 }).catch((err: BusinessError) => { 1450 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1451 }) 1452} catch (err) { 1453 let message = (err as BusinessError).message; 1454 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message); 1455} 1456``` 1457 1458## bundleManager.queryExtensionAbilityInfoSync<sup>10+</sup> 1459 1460queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: ExtensionAbilityType, extensionAbilityFlags: number, userId?: number): Array\<ExtensionAbilityInfo> 1461 1462以同步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo。 1463 1464**系统接口:** 此接口为系统接口。 1465 1466**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1467 1468**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1469 1470**参数:** 1471 1472| 参数名 | 类型 | 必填 | 说明 | 1473| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1474| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 1475| extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager-sys.md#extensionabilitytype) | 是 | 标识extensionAbility的类型。 | 1476| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 | 1477| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 1478 1479**返回值:** 1480 1481| 类型 | 说明 | 1482| ------------------------------------------------------------ | --------------------------------------------- | 1483| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | Array\<ExtensionAbilityInfo>信息。 | 1484 1485**错误码:** 1486 1487以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1488 1489| 错误码ID | 错误信息 | 1490| -------- | --------------------------------------| 1491| 201 | Permission denied. | 1492| 202 | Permission denied, non-system app called system api. | 1493| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 1494| 17700001 | The specified bundleName is not found. | 1495| 17700003 | The specified extensionAbility is not found. | 1496| 17700004 | The specified userId is invalid. | 1497| 17700026 | The specified bundle is disabled. | 1498 1499**示例:** 1500 1501```ts 1502import { bundleManager } from '@kit.AbilityKit'; 1503import { BusinessError } from '@kit.BasicServicesKit'; 1504import { hilog } from '@kit.PerformanceAnalysisKit'; 1505import { Want } from '@kit.AbilityKit'; 1506 1507let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1508let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1509let userId = 100; 1510let want: Want = { 1511 bundleName : "com.example.myapplication", 1512 abilityName : "EntryAbility" 1513}; 1514 1515try { 1516 let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId); 1517 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos)); 1518} catch (err) { 1519 let message = (err as BusinessError).message; 1520 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message); 1521} 1522``` 1523 1524```ts 1525import { bundleManager } from '@kit.AbilityKit'; 1526import { BusinessError } from '@kit.BasicServicesKit'; 1527import { hilog } from '@kit.PerformanceAnalysisKit'; 1528import { Want } from '@kit.AbilityKit'; 1529let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1530let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1531let want: Want = { 1532 bundleName : "com.example.myapplication", 1533 abilityName : "EntryAbility" 1534}; 1535 1536try { 1537 let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags); 1538 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos)); 1539} catch (err) { 1540 let message = (err as BusinessError).message; 1541 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message); 1542} 1543``` 1544 1545## bundleManager.getBundleNameByUid<sup>14+</sup> 1546 1547getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void 1548 1549根据给定的uid获取对应的bundleName,使用callback异步回调。 1550 1551**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1552 1553**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1554 1555**参数:** 1556 1557| 参数名 | 类型 | 必填 | 说明 | 1558| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1559| uid | number | 是 | 表示应用程序的UID。 | 1560| callback | AsyncCallback\<string> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleName;否则为错误对象。 | 1561 1562**错误码:** 1563 1564以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1565 1566| 错误码ID | 错误信息 | 1567| -------- | --------------------- | 1568| 201 | Permission denied. | 1569| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1570| 17700021 | The uid is not found. | 1571 1572**示例:** 1573 1574```ts 1575import { bundleManager } from '@kit.AbilityKit'; 1576import { BusinessError } from '@kit.BasicServicesKit'; 1577import { hilog } from '@kit.PerformanceAnalysisKit'; 1578let uid = 20010005; 1579try { 1580 bundleManager.getBundleNameByUid(uid, (err, data) => { 1581 if (err) { 1582 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message); 1583 } else { 1584 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data)); 1585 } 1586 }); 1587} catch (err) { 1588 let message = (err as BusinessError).message; 1589 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', message); 1590} 1591``` 1592 1593## bundleManager.getBundleNameByUid<sup>14+</sup> 1594 1595getBundleNameByUid(uid: number): Promise\<string> 1596 1597根据给定的uid获取对应的bundleName,使用Promise异步回调。 1598 1599**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1600 1601**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1602 1603**参数:** 1604 1605| 参数名 | 类型 | 必填 | 说明 | 1606| ---- | ------ | ---- | ------------------ | 1607| uid | number | 是 | 表示应用程序的UID。 | 1608 1609**返回值:** 1610 1611| 类型 | 说明 | 1612| ---------------- | --------------------------- | 1613| Promise\<string> | Promise对象,返回bundleName。 | 1614 1615**错误码:** 1616 1617以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1618 1619| 错误码ID | 错误信息 | 1620| -------- | ---------------------| 1621| 201 | Permission denied. | 1622| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1623| 17700021 | The uid is not found. | 1624 1625**示例:** 1626 1627```ts 1628import { bundleManager } from '@kit.AbilityKit'; 1629import { BusinessError } from '@kit.BasicServicesKit'; 1630import { hilog } from '@kit.PerformanceAnalysisKit'; 1631let uid = 20010005; 1632try { 1633 bundleManager.getBundleNameByUid(uid).then((data) => { 1634 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data)); 1635 }).catch((err: BusinessError) => { 1636 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message); 1637 }); 1638} catch (err) { 1639 let message = (err as BusinessError).message; 1640 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', message); 1641} 1642``` 1643 1644## bundleManager.getBundleNameByUidSync<sup>14+</sup> 1645 1646getBundleNameByUidSync(uid: number): string 1647 1648以同步方法根据给定的uid获取对应的bundleName。 1649 1650**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1651 1652**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1653 1654**参数:** 1655 1656| 参数名 | 类型 | 必填 | 说明 | 1657| ---- | ------ | ---- | ------------------ | 1658| uid | number | 是 | 表示应用程序的UID。 | 1659 1660**返回值:** 1661 1662| 类型 | 说明 | 1663| ---------------- | --------------------------- | 1664| string | 返回获取到的bundleName。 | 1665 1666**错误码:** 1667 1668以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1669 1670| 错误码ID | 错误信息 | 1671| -------- | ---------------------| 1672| 201 | Permission denied. | 1673| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1674| 17700021 | The uid is not found. | 1675 1676**示例:** 1677 1678```ts 1679import { bundleManager } from '@kit.AbilityKit'; 1680import { BusinessError } from '@kit.BasicServicesKit'; 1681import { hilog } from '@kit.PerformanceAnalysisKit'; 1682let uid = 20010005; 1683try { 1684 let data = bundleManager.getBundleNameByUidSync(uid); 1685 hilog.info(0x0000, 'testTag', 'getBundleNameByUidSync successfully. Data: %{public}s', JSON.stringify(data)); 1686} catch (err) { 1687 let message = (err as BusinessError).message; 1688 hilog.error(0x0000, 'testTag', 'getBundleNameByUidSync failed. Cause: %{public}s', message); 1689} 1690``` 1691 1692## bundleManager.getBundleArchiveInfo 1693 1694getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void 1695 1696根据给定的hapFilePath和bundleFlags获取BundleInfo,使用callback异步回调。 1697 1698**系统接口:** 此接口为系统接口。 1699 1700**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1701 1702**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1703 1704**参数:** 1705 1706| 参数名 | 类型 | 必填 | 说明 | 1707| ----------- | ------ | ---- | ----------------------------------------------------------- | 1708| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1709| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1710| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 | 1711 1712**错误码:** 1713 1714以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1715 1716| 错误码ID | 错误信息 | 1717| -------- | --------------------------- | 1718| 201 | Permission denied. | 1719| 202 | Permission denied, non-system app called system api. | 1720| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1721| 17700022 | The hapFilePath is invalid. | 1722 1723**示例:** 1724 1725```ts 1726import { bundleManager } from '@kit.AbilityKit'; 1727import { BusinessError } from '@kit.BasicServicesKit'; 1728import { hilog } from '@kit.PerformanceAnalysisKit'; 1729let hapFilePath = "/data/xxx/test.hap"; 1730let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1731 1732try { 1733 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => { 1734 if (err) { 1735 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1736 } else { 1737 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data)); 1738 } 1739 }); 1740} catch (err) { 1741 let message = (err as BusinessError).message; 1742 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message); 1743} 1744``` 1745 1746## bundleManager.getBundleArchiveInfo 1747 1748getBundleArchiveInfo(hapFilePath: string, bundleFlags: number): Promise\<BundleInfo> 1749 1750根据给定的hapFilePath和bundleFlags获取BundleInfo,使用Promise异步回调。 1751 1752**系统接口:** 此接口为系统接口。 1753 1754**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1755 1756**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1757 1758**参数:** 1759 1760| 参数名 | 类型 | 必填 | 说明 | 1761| ----------- | ------ | ---- | ------------------------------------------------------------ | 1762| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1763| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1764 1765**返回值:** 1766 1767| 类型 | 说明 | 1768| ----------------------------------------------------------- | --------------------------- | 1769| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 | 1770 1771**错误码:** 1772 1773以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1774 1775| 错误码ID | 错误信息 | 1776| -------- | -------------------------- | 1777| 201 | Permission denied. | 1778| 202 | Permission denied, non-system app called system api. | 1779| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1780| 17700022 | The hapFilePath is invalid. | 1781 1782**示例:** 1783 1784```ts 1785import { bundleManager } from '@kit.AbilityKit'; 1786import { BusinessError } from '@kit.BasicServicesKit'; 1787import { hilog } from '@kit.PerformanceAnalysisKit'; 1788let hapFilePath = "/data/xxx/test.hap"; 1789let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1790 1791try { 1792 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => { 1793 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data)); 1794 }).catch((err: BusinessError) => { 1795 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1796 }); 1797} catch (err) { 1798 let message = (err as BusinessError).message; 1799 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message); 1800} 1801``` 1802 1803## bundleManager.getBundleArchiveInfoSync<sup>10+</sup> 1804 1805getBundleArchiveInfoSync(hapFilePath: string, bundleFlags: number): BundleInfo 1806 1807以同步方法根据给定的hapFilePath和bundleFlags获取BundleInfo对象。 1808 1809**系统接口:** 此接口为系统接口。 1810 1811**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1812 1813**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1814 1815**参数:** 1816 1817| 参数名 | 类型 | 必填 | 说明 | 1818| ----------- | ------ | ---- | ------------------------------------------------------------ | 1819| hapFilePath | string | 是 | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 | 1820| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 1821 1822**返回值:** 1823 1824| 类型 | 说明 | 1825| ----------------------------------------------------------- | --------------------------- | 1826| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 1827 1828**错误码:** 1829 1830以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1831 1832| 错误码ID | 错误信息 | 1833| -------- | -------------------------- | 1834| 201 | Permission denied. | 1835| 202 | Permission denied, non-system app called system api. | 1836| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1837| 17700022 | The hapFilePath is invalid. | 1838 1839**示例:** 1840 1841```ts 1842import { bundleManager } from '@kit.AbilityKit'; 1843import { BusinessError } from '@kit.BasicServicesKit'; 1844import { hilog } from '@kit.PerformanceAnalysisKit'; 1845let hapFilePath = "/data/xxx/test.hap"; 1846let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1847 1848try { 1849 let data = bundleManager.getBundleArchiveInfoSync(hapFilePath, bundleFlags) 1850 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 1851} catch (err) { 1852 let message = (err as BusinessError).message; 1853 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfoSync failed. Cause: %{public}s', message); 1854} 1855``` 1856 1857## bundleManager.getAllBundleCacheSize<sup>15+</sup> 1858 1859getAllBundleCacheSize(): Promise\<number> 1860 1861获取全局缓存大小,使用Promise异步回调。 1862 1863**系统接口:** 此接口为系统接口。 1864 1865**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1866 1867**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1868 1869**返回值:** 1870 1871| 类型 | 说明 | 1872| ---------------------------------------- | ------- | 1873| Promise\<number> | Promise对象。返回全局缓存大小,以字节为单位。 | 1874 1875**错误码:** 1876 1877以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1878 1879| 错误码ID | 错误信息 | 1880| -------- | ---------------------------------------------------------- | 1881| 201 | Permission denied. | 1882| 202 | Permission denied, non-system app called system api. | 1883 1884**示例:** 1885 1886```ts 1887import { bundleManager } from '@kit.AbilityKit'; 1888import { BusinessError } from '@kit.BasicServicesKit'; 1889import { hilog } from '@kit.PerformanceAnalysisKit'; 1890 1891try { 1892 bundleManager.getAllBundleCacheSize().then((data) => { 1893 hilog.info(0x0000, 'testTag','getAllBundleCacheSize successful. Data: ' + JSON.stringify(data)); 1894 }).catch((err: BusinessError) => { 1895 hilog.error(0x0000, 'testTag', 'getAllBundleCacheSize failed: %{public}s', err.message); 1896 }); 1897} catch (err) { 1898 let message = (err as BusinessError).message; 1899 hilog.error(0x0000, 'testTag', 'getAllBundleCacheSize failed: %{public}s', message); 1900} 1901``` 1902 1903## bundleManager.cleanAllBundleCache<sup>15+</sup> 1904 1905cleanAllBundleCache(): Promise\<void> 1906 1907清理全局缓存,使用Promise异步回调。 1908 1909**系统接口:** 此接口为系统接口。 1910 1911**需要权限:** ohos.permission.REMOVE_CACHE_FILES 1912 1913**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1914 1915**返回值:** 1916 1917| 类型 | 说明 | 1918| ---------------------------------------- | ------- | 1919| Promise\<void> | 无返回结果的Promise对象。 | 1920 1921**错误码:** 1922 1923以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1924 1925| 错误码ID | 错误信息 | 1926| -------- | ---------------------------------------------------------- | 1927| 201 | Permission denied. | 1928| 202 | Permission denied, non-system app called system api. | 1929 1930**示例:** 1931 1932```ts 1933import { bundleManager } from '@kit.AbilityKit'; 1934import { BusinessError } from '@kit.BasicServicesKit'; 1935import { hilog } from '@kit.PerformanceAnalysisKit'; 1936 1937try { 1938 bundleManager.cleanAllBundleCache().then((data) => { 1939 hilog.info(0x0000, 'testTag','cleanAllBundleCache successful.'); 1940 }).catch((err: BusinessError) => { 1941 hilog.error(0x0000, 'testTag', 'cleanAllBundleCache failed: %{public}s', err.message); 1942 }); 1943} catch (err) { 1944 let message = (err as BusinessError).message; 1945 hilog.error(0x0000, 'testTag', 'cleanAllBundleCache failed: %{public}s', message); 1946} 1947``` 1948 1949## bundleManager.cleanBundleCacheFiles 1950 1951cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\<void>): void 1952 1953根据给定的bundleName清理BundleCache,使用callback异步回调。 1954 1955调用方清理自身缓存数据时不需要权限。 1956 1957**系统接口:** 此接口为系统接口。 1958 1959**需要权限:** ohos.permission.REMOVE_CACHE_FILES 1960 1961**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1962 1963**参数:** 1964 1965| 参数名 | 类型 | 必填 | 说明 | 1966| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 1967| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 1968| callback | AsyncCallback\<void> | 是 | 回调函数,当清理应用缓存目录数据成功,err为null,否则为错误对象。 | 1969 1970**错误码:** 1971 1972以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1973 1974| 错误码ID | 错误信息 | 1975| -------- | ------------------------------------------------------------ | 1976| 201 | Permission denied. | 1977| 202 | Permission denied, non-system app called system api. | 1978| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1979| 17700001 | The specified bundleName is not found. | 1980| 17700030 | The specified bundle does not support clearing of cache files. | 1981 1982**示例:** 1983 1984```ts 1985import { bundleManager } from '@kit.AbilityKit'; 1986import { BusinessError } from '@kit.BasicServicesKit'; 1987import { hilog } from '@kit.PerformanceAnalysisKit'; 1988let bundleName = "com.ohos.myapplication"; 1989 1990try { 1991 bundleManager.cleanBundleCacheFiles(bundleName, err => { 1992 if (err) { 1993 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1994 } else { 1995 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1996 } 1997 }); 1998} catch (err) { 1999 let message = (err as BusinessError).message; 2000 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 2001} 2002``` 2003 2004## bundleManager.cleanBundleCacheFiles 2005 2006cleanBundleCacheFiles(bundleName: string): Promise\<void> 2007 2008根据给定的bundleName清理BundleCache,使用Promise异步回调。 2009 2010调用方清理自身缓存数据时不需要权限。 2011 2012**系统接口:** 此接口为系统接口。 2013 2014**需要权限:** ohos.permission.REMOVE_CACHE_FILES 2015 2016**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2017 2018**参数:** 2019 2020| 参数名 | 类型 | 必填 | 说明 | 2021| ---------- | ------ | ---- | ------------------------------------------ | 2022| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 2023 2024**返回值:** 2025 2026| 类型 | 说明 | 2027| -------------- | ------------------------------------------------------------ | 2028| Promise\<void> | 无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。 | 2029 2030**错误码:** 2031 2032以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2033 2034| 错误码ID | 错误信息 | 2035| -------- | ---------------------------------------------------------- | 2036| 201 | Permission denied. | 2037| 202 | Permission denied, non-system app called system api. | 2038| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2039| 17700001 | The specified bundleName is not found. | 2040| 17700030 | The specified bundle does not support clearing of cache files. | 2041 2042**示例:** 2043 2044```ts 2045import { bundleManager } from '@kit.AbilityKit'; 2046import { BusinessError } from '@kit.BasicServicesKit'; 2047import { hilog } from '@kit.PerformanceAnalysisKit'; 2048let bundleName = "com.ohos.myapplication"; 2049 2050try { 2051 bundleManager.cleanBundleCacheFiles(bundleName).then(() => { 2052 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 2053 }).catch((err: BusinessError) => { 2054 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 2055 }); 2056} catch (err) { 2057 let message = (err as BusinessError).message; 2058 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 2059} 2060``` 2061 2062## bundleManager.cleanBundleCacheFiles<sup>15+</sup> 2063 2064cleanBundleCacheFiles(bundleName: string, appIndex: number): Promise\<void> 2065 2066根据给定的bundleName和appIndex清理BundleCache,使用Promise异步回调。 2067 2068调用方清理自身缓存数据时不需要权限。 2069 2070**系统接口:** 此接口为系统接口。 2071 2072**需要权限:** ohos.permission.REMOVE_CACHE_FILES 2073 2074**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2075 2076**参数:** 2077 2078| 参数名 | 类型 | 必填 | 说明 | 2079| ---------- | ------ | ---- | ------------------------------------------ | 2080| bundleName | string | 是 | 表示要清理其缓存数据的应用程序的bundleName。 | 2081| appIndex | number | 是 | 表示要清理其缓存数据的应用程序的分身应用索引。<br>appIndex为0时,表示清理主应用缓存数据。appIndex大于0时,表示清理指定分身应用缓存数据。 | 2082 2083**返回值:** 2084 2085| 类型 | 说明 | 2086| -------------- | ------------------------------------------------------------ | 2087| Promise\<void> | 无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。 | 2088 2089**错误码:** 2090 2091以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2092 2093| 错误码ID | 错误信息 | 2094| -------- | ---------------------------------------------------------- | 2095| 201 | Permission denied. | 2096| 202 | Permission denied, non-system app called system api. | 2097| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2098| 17700001 | The specified bundleName is not found. | 2099| 17700030 | The specified bundle does not support clearing of cache files. | 2100| 17700061 | AppIndex is not in the valid range. | 2101 2102**示例:** 2103 2104```ts 2105import { bundleManager } from '@kit.AbilityKit'; 2106import { BusinessError } from '@kit.BasicServicesKit'; 2107import { hilog } from '@kit.PerformanceAnalysisKit'; 2108let bundleName = "com.ohos.myapplication"; 2109let appIndex = 1; 2110 2111try { 2112 bundleManager.cleanBundleCacheFiles(bundleName, appIndex).then(() => { 2113 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 2114 }).catch((err: BusinessError) => { 2115 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 2116 }); 2117} catch (err) { 2118 let message = (err as BusinessError).message; 2119 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 2120} 2121``` 2122 2123## bundleManager.setApplicationEnabled 2124 2125setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\<void>): void 2126 2127设置指定应用的禁用或使能状态,使用callback异步回调。 2128 2129**系统接口:** 此接口为系统接口。 2130 2131**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2132 2133**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2134 2135**参数:** 2136 2137| 参数名 | 类型 | 必填 | 说明 | 2138| ---------- | ------- | ---- | ------------------------------------- | 2139| bundleName | string | 是 | 指定应用的bundleName。 | 2140| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2141| callback | AsyncCallback\<void> | 是 | 回调函数,当设置应用禁用或使能状态成功时,err为null,否则为错误对象。 | 2142 2143**错误码:** 2144 2145以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2146 2147| 错误码ID | 错误信息 | 2148| -------- | -------------------------------------- | 2149| 201 | Permission denied. | 2150| 202 | Permission denied, non-system app called system api. | 2151| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2152| 17700001 | The specified bundleName is not found. | 2153 2154**示例:** 2155 2156```ts 2157import { bundleManager } from '@kit.AbilityKit'; 2158import { BusinessError } from '@kit.BasicServicesKit'; 2159import { hilog } from '@kit.PerformanceAnalysisKit'; 2160let bundleName = "com.ohos.myapplication"; 2161 2162try { 2163 bundleManager.setApplicationEnabled(bundleName, false, err => { 2164 if (err) { 2165 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2166 } else { 2167 hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.'); 2168 } 2169 }); 2170} catch (err) { 2171 let message = (err as BusinessError).message; 2172 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2173} 2174``` 2175 2176## bundleManager.setApplicationEnabled 2177 2178setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\<void> 2179 2180设置指定应用的禁用或使能状态,使用Promise异步回调。 2181 2182**系统接口:** 此接口为系统接口。 2183 2184**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2185 2186**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2187 2188**参数:** 2189 2190| 参数名 | 类型 | 必填 | 说明 | 2191| ---------- | ------- | ---- | ------------------------------------- | 2192| bundleName | string | 是 | 表示应用程序的bundleName。 | 2193| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2194 2195**返回值:** 2196 2197| 类型 | 说明 | 2198| -------------- | ------------------------------------ | 2199| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2200 2201**错误码:** 2202 2203以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2204 2205| 错误码ID | 错误信息 | 2206| -------- | -------------------------------------- | 2207| 201 | Permission denied. | 2208| 202 | Permission denied, non-system app called system api. | 2209| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2210| 17700001 | The specified bundleName is not found. | 2211 2212**示例:** 2213 2214```ts 2215import { bundleManager } from '@kit.AbilityKit'; 2216import { BusinessError } from '@kit.BasicServicesKit'; 2217import { hilog } from '@kit.PerformanceAnalysisKit'; 2218let bundleName = "com.ohos.myapplication"; 2219 2220try { 2221 bundleManager.setApplicationEnabled(bundleName, false).then(() => { 2222 hilog.info(0x0000, "testTag", "setApplicationEnabled successfully."); 2223 }).catch((err: BusinessError) => { 2224 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2225 }); 2226} catch (err) { 2227 let message = (err as BusinessError).message; 2228 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2229} 2230``` 2231 2232## bundleManager.setApplicationEnabled<sup>12+</sup> 2233 2234setApplicationEnabled(bundleName: string, appIndex: number, isEnabled: boolean): Promise\<void> 2235 2236设置指定应用或分身应用的禁用或使能状态,使用Promise异步回调。 2237 2238**系统接口:** 此接口为系统接口。 2239 2240**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2241 2242**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2243 2244**参数:** 2245 2246| 参数名 | 类型 | 必填 | 说明 | 2247| ---------- | ------- | ---- | ------------------------------------- | 2248| bundleName | string | 是 | 表示应用程序的bundleName。 | 2249| appIndex | number | 是 | 表示分身应用的索引。<br> appIndex为0时,表示设置主应用的禁用或使能状态。appIndex大于0时,表示设置指定分身应用的禁用或使能状态。 | 2250| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2251 2252**返回值:** 2253 2254| 类型 | 说明 | 2255| -------------- | ------------------------------------ | 2256| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2257 2258**错误码:** 2259 2260以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2261 2262| 错误码ID | 错误信息 | 2263| -------- | -------------------------------------- | 2264| 201 | Permission denied. | 2265| 202 | Permission denied, non-system app called system api. | 2266| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2267| 17700001 | The specified bundleName is not found. | 2268| 17700061 | AppIndex is not in the valid range. | 2269 2270**示例:** 2271 2272```ts 2273import { bundleManager } from '@kit.AbilityKit'; 2274import { BusinessError } from '@kit.BasicServicesKit'; 2275import { hilog } from '@kit.PerformanceAnalysisKit'; 2276let bundleName = "com.ohos.myapplication"; 2277 2278try { 2279 bundleManager.setApplicationEnabled(bundleName, 1, false).then(() => { 2280 hilog.info(0x0000, "testTag", "setApplicationEnabled successfully."); 2281 }).catch((err: BusinessError) => { 2282 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2283 }); 2284} catch (err) { 2285 let message = (err as BusinessError).message; 2286 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2287} 2288``` 2289 2290## bundleManager.setApplicationEnabledSync<sup>10+</sup> 2291 2292setApplicationEnabledSync(bundleName: string, isEnabled: boolean): void 2293 2294以同步方法设置指定应用的禁用或使能状态。 2295 2296**系统接口:** 此接口为系统接口。 2297 2298**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2299 2300**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2301 2302**参数:** 2303 2304| 参数名 | 类型 | 必填 | 说明 | 2305| ---------- | ------- | ---- | ------------------------------------- | 2306| bundleName | string | 是 | 指定应用的bundleName。 | 2307| isEnabled | boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2308 2309**错误码:** 2310 2311以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2312 2313| 错误码ID | 错误信息 | 2314| -------- | -------------------------------------- | 2315| 201 | Permission denied. | 2316| 202 | Permission denied, non-system app called system api. | 2317| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2318| 17700001 | The specified bundleName is not found. | 2319 2320**示例:** 2321 2322```ts 2323import { bundleManager } from '@kit.AbilityKit'; 2324import { BusinessError } from '@kit.BasicServicesKit'; 2325import { hilog } from '@kit.PerformanceAnalysisKit'; 2326let bundleName = "com.ohos.myapplication"; 2327 2328try { 2329 bundleManager.setApplicationEnabledSync(bundleName, false); 2330 hilog.info(0x0000, 'testTag', 'setApplicationEnabledSync successfully.'); 2331} catch (err) { 2332 let message = (err as BusinessError).message; 2333 hilog.error(0x0000, 'testTag', 'setApplicationEnabledSync failed: %{public}s', message); 2334} 2335``` 2336 2337## bundleManager.setAbilityEnabled 2338 2339setAbilityEnabled(info: AbilityInfo, isEnabled: boolean, callback: AsyncCallback\<void>): void 2340 2341设置指定组件的禁用或使能状态,使用callback异步回调。 2342 2343**系统接口:** 此接口为系统接口。 2344 2345**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2346 2347**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2348 2349**参数:** 2350 2351| 参数名 | 类型 | 必填 | 说明 | 2352| -------- | ----------- | ---- | ------------------------------------- | 2353| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2354| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2355| callback | AsyncCallback\<void> | 是 | 回调函数,当设置组件禁用或使能状态成功时,err为null,否则为错误对象。 | 2356 2357**错误码:** 2358 2359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2360 2361| 错误码ID | 错误信息 | 2362| -------- | ---------------------------------------| 2363| 201 | Permission denied. | 2364| 202 | Permission denied, non-system app called system api. | 2365| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2366| 17700001 | The specified bundleName is not found. | 2367| 17700003 | The specified abilityInfo is not found. | 2368 2369**示例:** 2370 2371```ts 2372import { bundleManager } from '@kit.AbilityKit'; 2373import { BusinessError } from '@kit.BasicServicesKit'; 2374import { hilog } from '@kit.PerformanceAnalysisKit'; 2375import { Want } from '@kit.AbilityKit'; 2376let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2377let userId = 100; 2378let want: Want = { 2379 bundleName : "com.example.myapplication", 2380 abilityName : "EntryAbility" 2381}; 2382 2383try { 2384 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2385 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2386 let info = abilitiesInfo[0]; 2387 2388 bundleManager.setAbilityEnabled(info, false, err => { 2389 if (err) { 2390 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2391 } else { 2392 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2393 } 2394 }); 2395 }).catch((err: BusinessError) => { 2396 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2397 }); 2398} catch (err) { 2399 let message = (err as BusinessError).message; 2400 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2401} 2402``` 2403 2404## bundleManager.setAbilityEnabled 2405 2406setAbilityEnabled(info: AbilityInfo, isEnabled: boolean): Promise\<void> 2407 2408设置指定组件的禁用或使能状态,使用Promise异步回调。 2409 2410**系统接口:** 此接口为系统接口。 2411 2412**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2413 2414**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2415 2416**参数:** 2417 2418| 参数名 | 类型 | 必填 | 说明 | 2419| -------- | ----------- | ---- | ------------------------------------- | 2420| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2421| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2422 2423**返回值:** 2424 2425| 类型 | 说明 | 2426| -------------- | --------------------------------- | 2427| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2428 2429**错误码:** 2430 2431以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2432 2433| 错误码ID | 错误信息 | 2434| -------- | -------------------------------------- | 2435| 201 | Permission denied. | 2436| 202 | Permission denied, non-system app called system api. | 2437| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2438| 17700001 | The specified bundleName is not found. | 2439| 17700003 | The specified abilityInfo is not found. | 2440 2441**示例:** 2442 2443```ts 2444import { bundleManager } from '@kit.AbilityKit'; 2445import { BusinessError } from '@kit.BasicServicesKit'; 2446import { hilog } from '@kit.PerformanceAnalysisKit'; 2447import { Want } from '@kit.AbilityKit'; 2448let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2449let userId = 100; 2450let want: Want = { 2451 bundleName : "com.example.myapplication", 2452 abilityName : "EntryAbility" 2453}; 2454 2455try { 2456 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2457 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2458 let info = abilitiesInfo[0]; 2459 2460 bundleManager.setAbilityEnabled(info, false).then(() => { 2461 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2462 }).catch((err: BusinessError) => { 2463 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2464 }); 2465 }).catch((err: BusinessError) => { 2466 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2467 }); 2468} catch (err) { 2469 let message = (err as BusinessError).message; 2470 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2471} 2472``` 2473 2474## bundleManager.setAbilityEnabled<sup>12+</sup> 2475 2476setAbilityEnabled(info: AbilityInfo, appIndex: number, isEnabled: boolean): Promise\<void> 2477 2478设置指定应用或分身应用组件的禁用或使能状态,使用Promise异步回调。 2479 2480**系统接口:** 此接口为系统接口。 2481 2482**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2483 2484**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2485 2486**参数:** 2487 2488| 参数名 | 类型 | 必填 | 说明 | 2489| -------- | ----------- | ---- | ------------------------------------- | 2490| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2491| appIndex | number | 是 | 表示分身应用的索引。<br> appIndex为0时,表示设置主应用组件的禁用或使能状态。appIndex大于0时,表示设置指定分身应用组件的禁用或使能状态。 | 2492| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2493 2494**返回值:** 2495 2496| 类型 | 说明 | 2497| -------------- | --------------------------------- | 2498| Promise\<void> | Promise对象。无返回结果的Promise对象。 | 2499 2500**错误码:** 2501 2502以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2503 2504| 错误码ID | 错误信息 | 2505| -------- | -------------------------------------- | 2506| 201 | Permission denied. | 2507| 202 | Permission denied, non-system app called system api. | 2508| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2509| 17700001 | The specified bundleName is not found. | 2510| 17700003 | The specified abilityInfo is not found. | 2511| 17700061 | AppIndex is not in the valid range. | 2512 2513**示例:** 2514 2515```ts 2516import { bundleManager } from '@kit.AbilityKit'; 2517import { BusinessError } from '@kit.BasicServicesKit'; 2518import { hilog } from '@kit.PerformanceAnalysisKit'; 2519import { Want } from '@kit.AbilityKit'; 2520let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2521let userId = 100; 2522let want: Want = { 2523 bundleName : "com.example.myapplication", 2524 abilityName : "EntryAbility" 2525}; 2526 2527try { 2528 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2529 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2530 let info = abilitiesInfo[0]; 2531 2532 bundleManager.setAbilityEnabled(info, 1, false).then(() => { 2533 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2534 }).catch((err: BusinessError) => { 2535 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2536 }); 2537 }).catch((err: BusinessError) => { 2538 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2539 }); 2540} catch (err) { 2541 let message = (err as BusinessError).message; 2542 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2543} 2544``` 2545 2546## bundleManager.setAbilityEnabledSync<sup>10+</sup> 2547 2548setAbilityEnabledSync(info: AbilityInfo, isEnabled: boolean): void 2549 2550以同步方法设置指定组件的禁用或使能状态。 2551 2552**系统接口:** 此接口为系统接口。 2553 2554**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2555 2556**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2557 2558**参数:** 2559 2560| 参数名 | 类型 | 必填 | 说明 | 2561| -------- | ----------- | ---- | ------------------------------------- | 2562| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 需要被设置的组件。 | 2563| isEnabled| boolean | 是 | 值为true表示使能,值为false表示禁用。 | 2564 2565**错误码:** 2566 2567以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2568 2569| 错误码ID | 错误信息 | 2570| -------- | ---------------------------------------| 2571| 201 | Permission denied. | 2572| 202 | Permission denied, non-system app called system api. | 2573| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2574| 17700001 | The specified bundleName is not found. | 2575| 17700003 | The specified abilityInfo is not found. | 2576 2577**示例:** 2578 2579```ts 2580import { bundleManager } from '@kit.AbilityKit'; 2581import { BusinessError } from '@kit.BasicServicesKit'; 2582import { hilog } from '@kit.PerformanceAnalysisKit'; 2583import { Want } from '@kit.AbilityKit'; 2584let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2585let userId = 100; 2586let want: Want = { 2587 bundleName : "com.example.myapplication", 2588 abilityName : "EntryAbility" 2589}; 2590 2591try { 2592 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2593 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2594 let info = abilitiesInfo[0]; 2595 2596 try { 2597 bundleManager.setAbilityEnabledSync(info, false); 2598 hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully."); 2599 } catch (err) { 2600 let message = (err as BusinessError).message; 2601 hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', message); 2602 } 2603 }).catch((err: BusinessError) => { 2604 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2605 }); 2606} catch (err) { 2607 let message = (err as BusinessError).message; 2608 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2609} 2610``` 2611 2612## bundleManager.isApplicationEnabled 2613 2614isApplicationEnabled(bundleName: string, callback: AsyncCallback\<boolean>): void 2615 2616获取指定应用的禁用或使能状态,使用callback异步回调。 2617 2618**系统接口:** 此接口为系统接口。 2619 2620**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2621 2622**参数:** 2623 2624| 参数名 | 类型 | 必填 | 说明 | 2625| ---------- | ------ | ---- | -------------------------- | 2626| bundleName | string | 是 | 表示应用程序的bundleName。 | 2627| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。 | 2628 2629**错误码:** 2630 2631以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2632 2633| 错误码ID | 错误信息 | 2634| -------- | -------------------------------------- | 2635| 202 | Permission denied, non-system app called system api. | 2636| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2637| 17700001 | The specified bundleName is not found. | 2638 2639**示例:** 2640 2641```ts 2642import { bundleManager } from '@kit.AbilityKit'; 2643import { BusinessError } from '@kit.BasicServicesKit'; 2644import { hilog } from '@kit.PerformanceAnalysisKit'; 2645let bundleName = 'com.example.myapplication'; 2646 2647try { 2648 bundleManager.isApplicationEnabled(bundleName, (err, data) => { 2649 if (err) { 2650 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message); 2651 } else { 2652 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data)); 2653 } 2654 }); 2655} catch (err) { 2656 let message = (err as BusinessError).message; 2657 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', message); 2658} 2659``` 2660 2661## bundleManager.isApplicationEnabled 2662 2663isApplicationEnabled(bundleName: string): Promise\<boolean> 2664 2665获取指定应用的禁用或使能状态,使用Promise异步回调。 2666 2667**系统接口:** 此接口为系统接口。 2668 2669**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2670 2671**参数:** 2672 2673| 参数名 | 类型 | 必填 | 说明 | 2674| ---------- | ------ | ---- | -------------------------- | 2675| bundleName | string | 是 | 表示应用程序的bundleName。 | 2676 2677**返回值:** 2678 2679| 类型 | 说明 | 2680| ----------------- | ------------------------------------------------------------ | 2681| Promise\<boolean> | Promise对象,返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 | 2682 2683**错误码:** 2684 2685以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2686 2687| 错误码ID | 错误信息 | 2688| -------- | -------------------------------------- | 2689| 202 | Permission denied, non-system app called system api. | 2690| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2691| 17700001 | The specified bundleName is not found. | 2692 2693**示例:** 2694 2695```ts 2696import { bundleManager } from '@kit.AbilityKit'; 2697import { BusinessError } from '@kit.BasicServicesKit'; 2698import { hilog } from '@kit.PerformanceAnalysisKit'; 2699let bundleName = 'com.example.myapplication'; 2700 2701try { 2702 bundleManager.isApplicationEnabled(bundleName).then((data) => { 2703 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2704 }).catch((err: BusinessError) => { 2705 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message); 2706 }); 2707} catch (err) { 2708 let message = (err as BusinessError).message; 2709 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', message); 2710} 2711``` 2712 2713## bundleManager.isApplicationEnabled<sup>12+</sup> 2714 2715isApplicationEnabled(bundleName: string, appIndex: number): Promise\<boolean> 2716 2717获取指定应用或分身应用的禁用或使能状态,使用Promise异步回调。 2718 2719**系统接口:** 此接口为系统接口。 2720 2721**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2722 2723**参数:** 2724 2725| 参数名 | 类型 | 必填 | 说明 | 2726| ---------- | ------ | ---- | -------------------------- | 2727| bundleName | string | 是 | 表示应用程序的bundleName。 | 2728| appIndex | number | 是 | 表示分身应用的索引。<br> appIndex为0时,表示获取主应用的禁用或使能状态。appIndex大于0时,表示获取指定分身应用的禁用或使能状态。 | 2729 2730**返回值:** 2731 2732| 类型 | 说明 | 2733| ----------------- | ------------------------------------------------------------ | 2734| Promise\<boolean> | Promise对象,返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 | 2735 2736**错误码:** 2737 2738以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2739 2740| 错误码ID | 错误信息 | 2741| -------- | -------------------------------------- | 2742| 202 | Permission denied, non-system app called system api. | 2743| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2744| 17700001 | The specified bundleName is not found. | 2745| 17700061 | AppIndex is not in the valid range. | 2746 2747**示例:** 2748 2749```ts 2750import { bundleManager } from '@kit.AbilityKit'; 2751import { BusinessError } from '@kit.BasicServicesKit'; 2752import { hilog } from '@kit.PerformanceAnalysisKit'; 2753let bundleName = 'com.example.myapplication'; 2754 2755try { 2756 bundleManager.isApplicationEnabled(bundleName, 1).then((data) => { 2757 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2758 }).catch((err: BusinessError) => { 2759 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message); 2760 }); 2761} catch (err) { 2762 let message = (err as BusinessError).message; 2763 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', message); 2764} 2765``` 2766 2767## bundleManager.isApplicationEnabledSync<sup>10+</sup> 2768 2769isApplicationEnabledSync(bundleName: string): boolean 2770 2771以同步方法获取指定应用的禁用或使能状态。 2772 2773**系统接口:** 此接口为系统接口。 2774 2775**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2776 2777**参数:** 2778 2779| 参数名 | 类型 | 必填 | 说明 | 2780| ---------- | ------ | ---- | -------------------------- | 2781| bundleName | string | 是 | 表示应用程序的bundleName。 | 2782 2783**返回值:** 2784 2785| 类型 | 说明 | 2786| ------- | ------------------------------------------------------------ | 2787| boolean | 返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 | 2788 2789**错误码:** 2790 2791以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2792 2793| 错误码ID | 错误信息 | 2794| -------- | -------------------------------------- | 2795| 202 | Permission denied, non-system app called system api. | 2796| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2797| 17700001 | The specified bundleName is not found. | 2798 2799**示例:** 2800 2801```ts 2802import { bundleManager } from '@kit.AbilityKit'; 2803import { BusinessError } from '@kit.BasicServicesKit'; 2804import { hilog } from '@kit.PerformanceAnalysisKit'; 2805let bundleName = 'com.example.myapplication'; 2806 2807try { 2808 let data = bundleManager.isApplicationEnabledSync(bundleName); 2809 hilog.info(0x0000, 'testTag', 'isApplicationEnabledSync successfully: %{public}s', JSON.stringify(data)); 2810} catch (err) { 2811 let message = (err as BusinessError).message; 2812 hilog.error(0x0000, 'testTag', 'isApplicationEnabledSync failed: %{public}s', message); 2813} 2814``` 2815 2816## bundleManager.isAbilityEnabled 2817 2818isAbilityEnabled(info: AbilityInfo, callback: AsyncCallback\<boolean>): void 2819 2820获取指定组件的禁用或使能状态,使用callback异步回调。 2821 2822**系统接口:** 此接口为系统接口。 2823 2824**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2825 2826**参数:** 2827 2828| 参数名 | 类型 | 必填 | 说明 | 2829| ---- | ----------- | ---- | --------------------------- | 2830| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2831| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用组件为使能状态,返回false表示应用组件为禁用状态。 | 2832 2833**错误码:** 2834 2835以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2836 2837| 错误码ID | 错误信息 | 2838| -------- | --------------------------------------- | 2839| 202 | Permission denied, non-system app called system api. | 2840| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2841| 17700001 | The specified bundleName is not found. | 2842| 17700003 | The specified abilityName is not found. | 2843 2844**示例:** 2845 2846```ts 2847import { bundleManager } from '@kit.AbilityKit'; 2848import { BusinessError } from '@kit.BasicServicesKit'; 2849import { hilog } from '@kit.PerformanceAnalysisKit'; 2850import { Want } from '@kit.AbilityKit'; 2851let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2852let userId = 100; 2853let want: Want = { 2854 bundleName : "com.example.myapplication", 2855 abilityName : "EntryAbility" 2856}; 2857 2858try { 2859 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2860 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2861 let info = abilitiesInfo[0]; 2862 2863 bundleManager.isAbilityEnabled(info, (err, data) => { 2864 if (err) { 2865 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message); 2866 } else { 2867 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data)); 2868 } 2869 }); 2870 }).catch((err: BusinessError) => { 2871 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2872 }); 2873} catch (err) { 2874 let message = (err as BusinessError).message; 2875 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2876} 2877``` 2878 2879## bundleManager.isAbilityEnabled 2880 2881isAbilityEnabled(info: AbilityInfo): Promise\<boolean> 2882 2883获取指定组件的禁用或使能状态,使用Promise异步回调。 2884 2885**系统接口:** 此接口为系统接口。 2886 2887**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2888 2889**参数:** 2890 2891| 参数名 | 类型 | 必填 | 说明 | 2892| ---- | ----------- | ---- | --------------------------- | 2893| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2894 2895**返回值:** 2896 2897| 类型 | 说明 | 2898| ----------------- | ------------------------------------------------------------ | 2899| Promise\<boolean> | Promise对象,返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 | 2900 2901**错误码:** 2902 2903以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2904 2905| 错误码ID | 错误信息 | 2906| -------- | --------------------------------------- | 2907| 202 | Permission denied, non-system app called system api. | 2908| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2909| 17700001 | The specified bundleName is not found. | 2910| 17700003 | The specified abilityName is not found. | 2911 2912**示例:** 2913 2914```ts 2915import { bundleManager } from '@kit.AbilityKit'; 2916import { BusinessError } from '@kit.BasicServicesKit'; 2917import { hilog } from '@kit.PerformanceAnalysisKit'; 2918import { Want } from '@kit.AbilityKit'; 2919let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2920let userId = 100; 2921let want: Want = { 2922 bundleName : "com.example.myapplication", 2923 abilityName : "EntryAbility" 2924}; 2925 2926try { 2927 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2928 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2929 let info = abilitiesInfo[0]; 2930 2931 bundleManager.isAbilityEnabled(info).then((data) => { 2932 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2933 }).catch((err: BusinessError) => { 2934 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message); 2935 }); 2936 }).catch((err: BusinessError) => { 2937 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2938 }); 2939} catch (err) { 2940 let message = (err as BusinessError).message; 2941 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2942} 2943``` 2944 2945## bundleManager.isAbilityEnabled<sup>12+</sup> 2946 2947isAbilityEnabled(info: AbilityInfo, appIndex: number): Promise\<boolean> 2948 2949获取应用或指定分身应用组件的禁用或使能状态,使用Promise异步回调。 2950 2951**系统接口:** 此接口为系统接口。 2952 2953**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 2954 2955**参数:** 2956 2957| 参数名 | 类型 | 必填 | 说明 | 2958| ---- | ----------- | ---- | --------------------------- | 2959| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 2960| appIndex | number | 是 | 表示分身应用的索引。 <br> appIndex为0时,表示获取主应用组件的禁用或使能状态。appIndex大于0时,表示获取指定分身应用组件的禁用或使能状态。 | 2961 2962**返回值:** 2963 2964| 类型 | 说明 | 2965| ----------------- | ------------------------------------------------------------ | 2966| Promise\<boolean> | Promise对象,返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 | 2967 2968**错误码:** 2969 2970以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 2971 2972| 错误码ID | 错误信息 | 2973| -------- | --------------------------------------- | 2974| 202 | Permission denied, non-system app called system api. | 2975| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 2976| 17700001 | The specified bundleName is not found. | 2977| 17700003 | The specified abilityName is not found. | 2978| 17700061 | AppIndex is not in the valid range. | 2979 2980**示例:** 2981 2982```ts 2983import { bundleManager } from '@kit.AbilityKit'; 2984import { BusinessError } from '@kit.BasicServicesKit'; 2985import { hilog } from '@kit.PerformanceAnalysisKit'; 2986import { Want } from '@kit.AbilityKit'; 2987let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2988let userId = 100; 2989let want: Want = { 2990 bundleName : "com.example.myapplication", 2991 abilityName : "EntryAbility" 2992}; 2993 2994try { 2995 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2996 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2997 let info = abilitiesInfo[0]; 2998 2999 bundleManager.isAbilityEnabled(info, 1).then((data) => { 3000 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data)); 3001 }).catch((err: BusinessError) => { 3002 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message); 3003 }); 3004 }).catch((err: BusinessError) => { 3005 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 3006 }); 3007} catch (err) { 3008 let message = (err as BusinessError).message; 3009 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 3010} 3011``` 3012 3013## bundleManager.isAbilityEnabledSync<sup>10+</sup> 3014 3015isAbilityEnabledSync(info: AbilityInfo): boolean 3016 3017以同步方法获取指定组件的禁用或使能状态。 3018 3019**系统接口:** 此接口为系统接口。 3020 3021**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3022 3023**参数:** 3024 3025| 参数名 | 类型 | 必填 | 说明 | 3026| ---- | ----------- | ---- | --------------------------- | 3027| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是 | 表示关于检查ability的信息。 | 3028 3029**返回值:** 3030 3031| 类型 | 说明 | 3032| ------- | ------------------------------------------------------------------- | 3033| boolean | 返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 | 3034 3035**错误码:** 3036 3037以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3038 3039| 错误码ID | 错误信息 | 3040| -------- | --------------------------------------- | 3041| 202 | Permission denied, non-system app called system api. | 3042| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3043| 17700001 | The specified bundleName is not found. | 3044| 17700003 | The specified abilityName is not found. | 3045 3046**示例:** 3047 3048```ts 3049import { bundleManager } from '@kit.AbilityKit'; 3050import { BusinessError } from '@kit.BasicServicesKit'; 3051import { hilog } from '@kit.PerformanceAnalysisKit'; 3052import { Want } from '@kit.AbilityKit'; 3053let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 3054let userId = 100; 3055let want: Want = { 3056 bundleName : "com.example.myapplication", 3057 abilityName : "EntryAbility" 3058}; 3059 3060try { 3061 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 3062 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 3063 let info = abilitiesInfo[0]; 3064 3065 try { 3066 let data = bundleManager.isAbilityEnabledSync(info); 3067 hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data)); 3068 } catch (err) { 3069 let message = (err as BusinessError).message; 3070 hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', message); 3071 } 3072 }).catch((err: BusinessError) => { 3073 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 3074 }); 3075} catch (err) { 3076 let message = (err as BusinessError).message; 3077 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 3078} 3079``` 3080 3081## bundleManager.getLaunchWantForBundle 3082 3083getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\<Want>): void 3084 3085根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback异步回调。 3086 3087**系统接口:** 此接口为系统接口。 3088 3089**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3090 3091**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3092 3093**参数:** 3094 3095| 参数名 | 类型 | 必填 | 说明 | 3096| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 3097| bundleName | string | 是 | 表示应用程序的bundleName。 | 3098| userId | number | 是 | 表示用户ID。 | 3099| callback | AsyncCallback\<Want> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 | 3100 3101**错误码:** 3102 3103以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3104 3105| 错误码ID | 错误信息 | 3106| -------- | --------------------------------------| 3107| 201 | Calling interface without permission 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'. | 3108| 202 | Permission denied, non-system app called system api. | 3109| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3110| 17700001 | The specified bundleName is not found. | 3111| 17700004 | The specified user ID is not found. | 3112| 17700026 | The specified bundle is disabled. | 3113 3114**示例:** 3115 3116```ts 3117import { bundleManager } from '@kit.AbilityKit'; 3118import { BusinessError } from '@kit.BasicServicesKit'; 3119import { hilog } from '@kit.PerformanceAnalysisKit'; 3120let bundleName = 'com.example.myapplication'; 3121let userId = 100; 3122 3123try { 3124 bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => { 3125 if (err) { 3126 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 3127 } else { 3128 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 3129 } 3130 }); 3131} catch (err) { 3132 let message = (err as BusinessError).message; 3133 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message); 3134} 3135``` 3136 3137## bundleManager.getLaunchWantForBundle 3138 3139getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void 3140 3141根据给定的bundleName获取用于启动应用程序的Want参数,使用callback异步回调。 3142 3143**系统接口:** 此接口为系统接口。 3144 3145**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3146 3147**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3148 3149**参数:** 3150 3151| 参数名 | 类型 | 必填 | 说明 | 3152| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 3153| bundleName | string | 是 | 表示应用程序的bundleName。 | 3154| callback | AsyncCallback\<Want> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 | 3155 3156**错误码:** 3157 3158以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3159 3160| 错误码ID | 错误信息 | 3161| -------- | --------------------------------------| 3162| 201 | Calling interface without permission 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'. | 3163| 202 | Permission denied, non-system app called system api. | 3164| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3165| 17700001 | The specified bundleName is not found. | 3166| 17700026 | The specified bundle is disabled. | 3167 3168**示例:** 3169 3170```ts 3171import { bundleManager } from '@kit.AbilityKit'; 3172import { BusinessError } from '@kit.BasicServicesKit'; 3173import { hilog } from '@kit.PerformanceAnalysisKit'; 3174let bundleName = 'com.example.myapplication'; 3175 3176try { 3177 bundleManager.getLaunchWantForBundle(bundleName, (err, data) => { 3178 if (err) { 3179 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 3180 } else { 3181 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 3182 } 3183 }); 3184} catch (err) { 3185 let message = (err as BusinessError).message; 3186 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message); 3187} 3188``` 3189 3190## bundleManager.getLaunchWantForBundle 3191 3192getLaunchWantForBundle(bundleName: string, userId?: number): Promise\<Want> 3193 3194根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise异步回调。 3195 3196**系统接口:** 此接口为系统接口。 3197 3198**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3199 3200**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3201 3202**参数:** 3203 3204| 参数名 | 类型 | 必填 | 说明 | 3205| ---------- | ------ | ---- | ------------------------- | 3206| bundleName | string | 是 | 表示应用程序的bundleName。 | 3207| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 3208 3209**返回值:** 3210 3211| 类型 | 说明 | 3212| -------------- | ------------------------- | 3213| Promise\<Want> | Promise对象,返回Want对象。 | 3214 3215**错误码:** 3216 3217以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3218 3219| 错误码ID | 错误信息 | 3220| -------- | --------------------------------------| 3221| 201 | Calling interface without permission 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'. | 3222| 202 | Permission denied, non-system app called system api. | 3223| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3224| 17700001 | The specified bundleName is not found. | 3225| 17700004 | The specified user ID is not found. | 3226| 17700026 | The specified bundle is disabled. | 3227 3228**示例:** 3229 3230```ts 3231import { bundleManager } from '@kit.AbilityKit'; 3232import { BusinessError } from '@kit.BasicServicesKit'; 3233import { hilog } from '@kit.PerformanceAnalysisKit'; 3234let bundleName = 'com.example.myapplication'; 3235let userId = 100; 3236 3237try { 3238 bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => { 3239 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data)); 3240 }).catch((err: BusinessError) => { 3241 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message); 3242 }); 3243} catch (err) { 3244 let message = (err as BusinessError).message; 3245 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', message); 3246} 3247``` 3248 3249 3250## bundleManager.getLaunchWantForBundleSync<sup>10+</sup> 3251 3252getLaunchWantForBundleSync(bundleName: string, userId?: number): Want 3253 3254以同步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数。 3255 3256**系统接口:** 此接口为系统接口。 3257 3258**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3259 3260**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3261 3262**参数:** 3263 3264| 参数名 | 类型 | 必填 | 说明 | 3265| ---------- | ------ | ---- | ------------------------- | 3266| bundleName | string | 是 | 表示应用程序的bundleName。 | 3267| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 3268 3269**返回值:** 3270 3271| 类型 | 说明 | 3272| -------------- | ------------------------- | 3273| Want | Want对象。 | 3274 3275**错误码:** 3276 3277以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3278 3279| 错误码ID | 错误信息 | 3280| -------- | --------------------------------------| 3281| 201 | Calling interface without permission 'ohos.permission.GET_BUNDLE_INFO_PRIVILEGED'. | 3282| 202 | Permission denied, non-system app called system api. | 3283| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3284| 17700001 | The specified bundleName is not found. | 3285| 17700004 | The specified user ID is not found. | 3286| 17700026 | The specified bundle is disabled. | 3287 3288**示例:** 3289 3290```ts 3291import { bundleManager } from '@kit.AbilityKit'; 3292import { BusinessError } from '@kit.BasicServicesKit'; 3293import { hilog } from '@kit.PerformanceAnalysisKit'; 3294import { Want } from '@kit.AbilityKit'; 3295let bundleName = 'com.example.myapplication'; 3296let userId = 100; 3297 3298try { 3299 let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName, userId); 3300 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); 3301} catch (err) { 3302 let message = (err as BusinessError).message; 3303 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message); 3304} 3305``` 3306 3307```ts 3308import { bundleManager } from '@kit.AbilityKit'; 3309import { BusinessError } from '@kit.BasicServicesKit'; 3310import { hilog } from '@kit.PerformanceAnalysisKit'; 3311import { Want } from '@kit.AbilityKit'; 3312let bundleName = 'com.example.myapplication'; 3313let userId = 100; 3314 3315try { 3316 let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName); 3317 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); 3318} catch (err) { 3319 let message = (err as BusinessError).message; 3320 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message); 3321} 3322``` 3323 3324## bundleManager.getPermissionDef 3325 3326getPermissionDef(permissionName: string, callback: AsyncCallback\<PermissionDef>): void 3327 3328根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback异步回调。 3329 3330**系统接口:** 此接口为系统接口。 3331 3332**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3333 3334**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3335 3336**参数:** 3337 3338| 参数名 | 类型 | 必填 | 说明 | 3339| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3340| permissionName | string | 是 | 表示权限名称。 | 3341| callback | AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef-sys.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<PermissionDef>;否则为错误对象。 | 3342 3343**错误码:** 3344 3345以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3346 3347| 错误码ID | 错误信息 | 3348| -------- | ------------------------------------- | 3349| 201 | Permission denied. | 3350| 202 | Permission denied, non-system app called system api. | 3351| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3352| 17700006 | The specified permission is not found. | 3353 3354**示例:** 3355 3356```ts 3357import { bundleManager } from '@kit.AbilityKit'; 3358import { BusinessError } from '@kit.BasicServicesKit'; 3359import { hilog } from '@kit.PerformanceAnalysisKit'; 3360let permission = "ohos.permission.GET_BUNDLE_INFO"; 3361try { 3362 bundleManager.getPermissionDef(permission, (err, data) => { 3363 if (err) { 3364 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message); 3365 } else { 3366 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data)); 3367 } 3368 }); 3369} catch (err) { 3370 let message = (err as BusinessError).message; 3371 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', message); 3372} 3373``` 3374 3375## bundleManager.getPermissionDef 3376 3377getPermissionDef(permissionName: string): Promise\<PermissionDef> 3378 3379根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise异步回调。 3380 3381**系统接口:** 此接口为系统接口。 3382 3383**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3384 3385**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3386 3387**参数:** 3388 3389| 参数名 | 类型 | 必填 | 说明 | 3390| -------------- | ------ | ---- | -------------- | 3391| permissionName | string | 是 | 表示权限参数名。 | 3392 3393**返回值:** 3394 3395| 类型 | 说明 | 3396| ------------------------------------------------------------ | ------------------------------------------ | 3397| Promise\<[PermissionDef](js-apis-bundleManager-permissionDef-sys.md)> | Promise对象,返回Array\<PermissionDef>对象。 | 3398 3399**错误码:** 3400 3401以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3402 3403| 错误码ID | 错误信息 | 3404| -------- | ------------------------------------- | 3405| 201 | Permission denied. | 3406| 202 | Permission denied, non-system app called system api. | 3407| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3408| 17700006 | The specified permission is not found. | 3409 3410**示例:** 3411 3412```ts 3413import { bundleManager } from '@kit.AbilityKit'; 3414import { BusinessError } from '@kit.BasicServicesKit'; 3415import { hilog } from '@kit.PerformanceAnalysisKit'; 3416let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 3417try { 3418 bundleManager.getPermissionDef(permissionName).then((data) => { 3419 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data)); 3420 }).catch((err: BusinessError) => { 3421 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message); 3422 }); 3423} catch (err) { 3424 let message = (err as BusinessError).message; 3425 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', message); 3426} 3427``` 3428 3429## bundleManager.getPermissionDefSync<sup>10+</sup> 3430 3431getPermissionDefSync(permissionName: string): PermissionDef; 3432 3433以同步方法根据给定的permissionName获取权限定义结构体PermissionDef信息。 3434 3435**系统接口:** 此接口为系统接口。 3436 3437**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3438 3439**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3440 3441**参数:** 3442 3443| 参数名 | 类型 | 必填 | 说明 | 3444| -------------- | ------ | ---- | -------------- | 3445| permissionName | string | 是 | 表示权限参数名。 | 3446 3447**返回值:** 3448 3449| 类型 | 说明 | 3450| ------------------------------------------------------------ | ------------------------------------------ | 3451|[PermissionDef](js-apis-bundleManager-permissionDef-sys.md) | PermissionDef对象。 | 3452 3453**错误码:** 3454 3455以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3456 3457| 错误码ID | 错误信息 | 3458| -------- | ------------------------------------- | 3459| 201 | Permission denied. | 3460| 202 | Permission denied, non-system app called system api. | 3461| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3462| 17700006 | The specified permission is not found. | 3463 3464**示例:** 3465 3466```ts 3467import { bundleManager } from '@kit.AbilityKit'; 3468import { BusinessError } from '@kit.BasicServicesKit'; 3469import { hilog } from '@kit.PerformanceAnalysisKit'; 3470let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 3471try { 3472 let PermissionDef = bundleManager.getPermissionDefSync(permissionName); 3473 hilog.info(0x0000, 'testTag', 'getPermissionDefSync successfully. Data: %{public}s', JSON.stringify(PermissionDef)); 3474} catch (err) { 3475 let message = (err as BusinessError).message; 3476 hilog.error(0x0000, 'testTag', 'getPermissionDefSync failed. Cause: %{public}s', message); 3477} 3478``` 3479 3480## bundleManager.getAbilityLabel 3481 3482getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<string>): void 3483 3484获取指定bundleName、moduleName和abilityName的label,使用callback异步回调。 3485 3486**系统接口:** 此接口为系统接口。 3487 3488**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3489 3490**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 3491 3492**参数:** 3493 3494| 参数名 | 类型 | 必填 | 说明 | 3495| ----------- | ---------------------- | ---- | ------------------------------------------------------------ | 3496| bundleName | string | 是 | 表示应用程序的bundleName。 | 3497| moduleName | string | 是 | 表示Module名称。 | 3498| abilityName | string | 是 | 表示UIAbility组件的名称。 | 3499| callback | AsyncCallback\<string> | 是 | 回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。 | 3500 3501**错误码:** 3502 3503以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3504 3505| 错误码ID | 错误信息 | 3506| -------- | -------------------------------------- | 3507| 201 | Permission denied. | 3508| 202 | Permission denied, non-system app called system api. | 3509| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3510| 801 | Capability not supported. | 3511| 17700001 | The specified bundleName is not found. | 3512| 17700002 | The specified moduleName is not found. | 3513| 17700003 | The specified abilityName is not found. | 3514| 17700026 | The specified bundle is disabled. | 3515| 17700029 | The specified ability is disabled. | 3516 3517**示例:** 3518 3519```ts 3520import { bundleManager } from '@kit.AbilityKit'; 3521import { BusinessError } from '@kit.BasicServicesKit'; 3522import { hilog } from '@kit.PerformanceAnalysisKit'; 3523let bundleName = 'com.example.myapplication'; 3524let moduleName = 'entry'; 3525let abilityName = 'EntryAbility'; 3526 3527try { 3528 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => { 3529 if (err) { 3530 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message); 3531 } else { 3532 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data)); 3533 } 3534 }); 3535} catch (err) { 3536 let message = (err as BusinessError).message; 3537 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', message); 3538} 3539``` 3540 3541## bundleManager.getAbilityLabel 3542 3543getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string> 3544 3545获取指定bundleName、moduleName和abilityName的label,使用Promise异步回调。 3546 3547**系统接口:** 此接口为系统接口。 3548 3549**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3550 3551**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 3552 3553**参数:** 3554 3555| 参数名 | 类型 | 必填 | 说明 | 3556| ----------- | ------ | ---- | ------------------------- | 3557| bundleName | string | 是 | 表示应用程序的bundleName。 | 3558| moduleName | string | 是 | 表示Module名称。 | 3559| abilityName | string | 是 | 表示UIAbility组件的名称。 | 3560 3561**返回值:** 3562 3563| 类型 | 说明 | 3564| ---------------- | ----------------------------------- | 3565| Promise\<string> | Promise对象,返回指定组件的Lablel值。 | 3566 3567**错误码:** 3568 3569以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3570 3571| 错误码ID | 错误信息 | 3572| -------- | --------------------------------------- | 3573| 201 | Permission denied. | 3574| 202 | Permission denied, non-system app called system api. | 3575| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3576| 801 | Capability not supported. | 3577| 17700001 | The specified bundleName is not found. | 3578| 17700002 | The specified moduleName is not found. | 3579| 17700003 | The specified abilityName is not found. | 3580| 17700026 | The specified bundle is disabled. | 3581| 17700029 | The specified ability is disabled. | 3582 3583**示例:** 3584 3585```ts 3586import { bundleManager } from '@kit.AbilityKit'; 3587import { BusinessError } from '@kit.BasicServicesKit'; 3588import { hilog } from '@kit.PerformanceAnalysisKit'; 3589let bundleName = 'com.example.myapplication'; 3590let moduleName = 'entry'; 3591let abilityName = 'EntryAbility'; 3592 3593try { 3594 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => { 3595 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data)); 3596 }).catch((err: BusinessError) => { 3597 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message); 3598 }); 3599} catch (err) { 3600 let message = (err as BusinessError).message; 3601 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', message); 3602} 3603``` 3604 3605## bundleManager.getAbilityLabelSync<sup>10+</sup> 3606 3607getAbilityLabelSync(bundleName: string, moduleName: string, abilityName: string): string 3608 3609以同步的方法获取指定bundleName、moduleName和abilityName的label。 3610 3611**系统接口:** 此接口为系统接口。 3612 3613**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3614 3615**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource 3616 3617**参数:** 3618 3619| 参数名 | 类型 | 必填 | 说明 | 3620| ----------- | ------ | ---- | ------------------------- | 3621| bundleName | string | 是 | 表示应用程序的bundleName。 | 3622| moduleName | string | 是 | 表示Module名称。 | 3623| abilityName | string | 是 | 表示UIAbility组件的名称。 | 3624 3625**返回值:** 3626 3627| 类型 | 说明 | 3628| ---------------- | ----------------------------------- | 3629| string | 指定组件的Lablel值。 | 3630 3631**错误码:** 3632 3633以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3634 3635| 错误码ID | 错误信息 | 3636| -------- | --------------------------------------- | 3637| 201 | Permission denied. | 3638| 202 | Permission denied, non-system app called system api. | 3639| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3640| 801 | Capability not supported. | 3641| 17700001 | The specified bundleName is not found. | 3642| 17700002 | The specified moduleName is not found. | 3643| 17700003 | The specified abilityName is not found. | 3644| 17700026 | The specified bundle is disabled. | 3645| 17700029 | The specified ability is disabled. | 3646 3647**示例:** 3648 3649```ts 3650import { bundleManager } from '@kit.AbilityKit'; 3651import { BusinessError } from '@kit.BasicServicesKit'; 3652import { hilog } from '@kit.PerformanceAnalysisKit'; 3653let bundleName = 'com.example.myapplication'; 3654let moduleName = 'entry'; 3655let abilityName = 'EntryAbility'; 3656 3657try { 3658 let abilityLabel = bundleManager.getAbilityLabelSync(bundleName, moduleName, abilityName); 3659 hilog.info(0x0000, 'testTag', 'getAbilityLabelSync successfully. Data: %{public}s', abilityLabel); 3660} catch (err) { 3661 let message = (err as BusinessError).message; 3662 hilog.error(0x0000, 'testTag', 'getAbilityLabelSync failed. Cause: %{public}s', message); 3663} 3664``` 3665 3666## bundleManager.getApplicationInfoSync 3667 3668getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : ApplicationInfo 3669 3670以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。 3671 3672**系统接口:** 此接口为系统接口。 3673 3674**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3675 3676**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3677 3678**参数:** 3679 3680| 参数名 | 类型 | 必填 | 说明 | 3681| ----------- | ------ | ---- | ----------------------------------------------------------| 3682| bundleName | string | 是 | 表示应用程序的bundleName。 | 3683| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | 3684| userId | number | 是 | 表示用户ID。 | 3685 3686**返回值:** 3687 3688| 类型 | 说明 | 3689| --------------- | ------------------------- | 3690| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | 3691 3692**错误码:** 3693 3694以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3695 3696| 错误码ID | 错误信息 | 3697| -------- | -------------------------------------- | 3698| 201 | Permission denied. | 3699| 202 | Permission denied, non-system app called system api. | 3700| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3701| 17700001 | The specified bundleName is not found. | 3702| 17700004 | The specified user ID is not found. | 3703| 17700026 | The specified bundle is disabled. | 3704 3705**示例:** 3706 3707```ts 3708import { bundleManager } from '@kit.AbilityKit'; 3709import { BusinessError } from '@kit.BasicServicesKit'; 3710import { hilog } from '@kit.PerformanceAnalysisKit'; 3711let bundleName = 'com.example.myapplication'; 3712let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 3713let userId = 100; 3714 3715try { 3716 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId); 3717 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 3718} catch (err) { 3719 let message = (err as BusinessError).message; 3720 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message); 3721} 3722``` 3723 3724## bundleManager.getApplicationInfoSync 3725 3726getApplicationInfoSync(bundleName: string, applicationFlags: number) : ApplicationInfo 3727 3728以同步方法根据给定的bundleName、applicationFlags获取ApplicationInfo。 3729 3730**系统接口:** 此接口为系统接口。 3731 3732**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3733 3734**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3735 3736**参数:** 3737 3738| 参数名 | 类型 | 必填 | 说明 | 3739| ---------------- | -------------------------- | ---- | ----------------------------------------------------- | 3740| bundleName | string | 是 | 表示应用程序的bundleName。 | 3741| applicationFlags | [number](#applicationflag) | 是 | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 | 3742 3743**返回值:** 3744 3745| 类型 | 说明 | 3746| ----------------------------------------------------------- | ------------------------- | 3747| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 | 3748 3749**错误码:** 3750 3751以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3752 3753| 错误码ID | 错误信息 | 3754| -------- | -------------------------------------- | 3755| 201 | Permission denied. | 3756| 202 | Permission denied, non-system app called system api. | 3757| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3758| 17700001 | The specified bundleName is not found. | 3759| 17700026 | The specified bundle is disabled. | 3760 3761**示例:** 3762 3763```ts 3764import { bundleManager } from '@kit.AbilityKit'; 3765import { BusinessError } from '@kit.BasicServicesKit'; 3766import { hilog } from '@kit.PerformanceAnalysisKit'; 3767let bundleName = 'com.example.myapplication'; 3768let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 3769 3770try { 3771 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags); 3772 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 3773} catch (err) { 3774 let message = (err as BusinessError).message; 3775 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message); 3776} 3777``` 3778 3779## bundleManager.getBundleInfoSync<sup>14+</sup> 3780 3781getBundleInfoSync(bundleName: string, bundleFlags: number, userId: number): BundleInfo 3782 3783以同步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo。 3784 3785获取调用方自己的信息时不需要权限。 3786 3787**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3788 3789**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3790 3791**参数:** 3792 3793| 参数名 | 类型 | 必填 | 说明 | 3794| ----------- | ------ | ---- | -------------------------------------------------------- | 3795| bundleName | string | 是 | 表示应用程序的bundleName。 | 3796| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | 3797| userId | number | 是 | 表示用户ID。 | 3798 3799**返回值:** 3800 3801| 类型 | 说明 | 3802| ---------- | -------------------- | 3803| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 3804 3805**错误码:** 3806 3807以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3808 3809| 错误码ID | 错误信息 | 3810| -------- | ------------------------------------- | 3811| 201 | Permission denied. | 3812| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3813| 17700001 | The specified bundleName is not found. | 3814| 17700004 | The specified user ID is not found. | 3815| 17700026 | The specified bundle is disabled. | 3816 3817**示例:** 3818 3819```ts 3820import { bundleManager } from '@kit.AbilityKit'; 3821import { BusinessError } from '@kit.BasicServicesKit'; 3822import { hilog } from '@kit.PerformanceAnalysisKit'; 3823let bundleName = 'com.example.myapplication'; 3824let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 3825let userId = 100; 3826 3827try { 3828 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId); 3829 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 3830} catch (err) { 3831 let message = (err as BusinessError).message; 3832 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message); 3833} 3834``` 3835 3836## bundleManager.getBundleInfoSync<sup>14+</sup> 3837 3838getBundleInfoSync(bundleName: string, bundleFlags: number): BundleInfo 3839 3840以同步方法根据给定的bundleName、bundleFlags获取BundleInfo。 3841 3842获取调用方自己的信息时不需要权限。 3843 3844**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3845 3846**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3847 3848**参数:** 3849 3850| 参数名 | 类型 | 必填 | 说明 | 3851| ----------- | --------------------- | ---- | ------------------------------------------------------ | 3852| bundleName | string | 是 | 表示应用程序的bundleName。 | 3853| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 | 3854 3855**返回值:** 3856 3857| 类型 | 说明 | 3858| ------------------------------------------------- | -------------------- | 3859| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 | 3860 3861**错误码:** 3862 3863以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3864 3865| 错误码ID | 错误信息 | 3866| -------- | -------------------------------------- | 3867| 201 | Permission denied. | 3868| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3869| 17700001 | The specified bundleName is not found. | 3870| 17700026 | The specified bundle is disabled. | 3871 3872**示例:** 3873 3874```ts 3875import { bundleManager } from '@kit.AbilityKit'; 3876import { BusinessError } from '@kit.BasicServicesKit'; 3877import { hilog } from '@kit.PerformanceAnalysisKit'; 3878let bundleName = 'com.example.myapplication'; 3879let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 3880try { 3881 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags); 3882 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 3883} catch (err) { 3884 let message = (err as BusinessError).message; 3885 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message); 3886} 3887``` 3888 3889## bundleManager.getSharedBundleInfo<sup>10+</sup> 3890 3891getSharedBundleInfo(bundleName: string, moduleName: string, callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void 3892 3893获取指定的共享包信息,使用callback异步回调。 3894 3895**系统接口:** 此接口为系统接口。 3896 3897**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3898 3899**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3900 3901**参数:** 3902 3903| 参数名 | 类型 | 必填 | 说明 | 3904| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3905| bundleName | string | 是 | 表示应用程序的bundleName。 | 3906| moduleName | string | 是 | 表示被查询的module的name。 | 3907| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo-sys.md)\>\> | 是 | 回调函数,当获取成功时,err为null,data为获取的指定共享包信息。 | 3908 3909**错误码:** 3910 3911以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3912 3913| 错误码ID | 错误信息 | 3914| -------- | -------------------------------------- | 3915| 201 | Permission denied. | 3916| 202 | Permission denied, non-system app called system api. | 3917| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3918| 17700001 | The specified bundleName is not found. | 3919| 17700002 | The specified moduleName is not found. | 3920 3921**示例:** 3922 3923```ts 3924import { bundleManager } from '@kit.AbilityKit'; 3925import { BusinessError } from '@kit.BasicServicesKit'; 3926import { hilog } from '@kit.PerformanceAnalysisKit'; 3927let bundleName = 'com.example.myapplication'; 3928let moduleName = 'library'; 3929 3930try { 3931 bundleManager.getSharedBundleInfo(bundleName, moduleName, (err, data) => { 3932 if (err) { 3933 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', err.message); 3934 } else { 3935 hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully: %{public}s', JSON.stringify(data)); 3936 } 3937 }); 3938} catch (err) { 3939 let message = (err as BusinessError).message; 3940 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', message); 3941} 3942``` 3943 3944## bundleManager.getSharedBundleInfo<sup>10+</sup> 3945 3946getSharedBundleInfo(bundleName: string, moduleName: string): Promise\<Array\<SharedBundleInfo\>\> 3947 3948获取指定的共享包信息,使用Promise异步回调。 3949 3950**系统接口:** 此接口为系统接口 3951 3952**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3953 3954**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 3955 3956**参数:** 3957 3958| 参数名 | 类型 | 必填 | 说明 | 3959| ---------- | ------ | ---- | -------------------------- | 3960| bundleName | string | 是 | 表示应用程序的bundleName。 | 3961| moduleName | string | 是 | 表示被查询的module的name。 | 3962 3963**返回值:** 3964 3965| 类型 | 说明 | 3966| ------------------------------------------------------------ | ----------------------------------- | 3967| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo-sys.md)\>\> | Promise对象,返回指定的共享包信息。 | 3968 3969**错误码:** 3970 3971以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 3972 3973| 错误码ID | 错误信息 | 3974| -------- | -------------------------------------- | 3975| 201 | Permission denied. | 3976| 202 | Permission denied, non-system app called system api. | 3977| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 3978| 17700001 | The specified bundleName is not found. | 3979| 17700002 | The specified moduleName is not found. | 3980 3981**示例:** 3982 3983```ts 3984import { bundleManager } from '@kit.AbilityKit'; 3985import { BusinessError } from '@kit.BasicServicesKit'; 3986import { hilog } from '@kit.PerformanceAnalysisKit'; 3987let bundleName = 'com.example.myapplication'; 3988let moduleName = 'library'; 3989 3990try { 3991 bundleManager.getSharedBundleInfo(bundleName, moduleName).then((data) => { 3992 hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 3993 }).catch((err: BusinessError) => { 3994 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', err.message); 3995 }); 3996} catch (err) { 3997 let message = (err as BusinessError).message; 3998 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', message); 3999} 4000``` 4001 4002## bundleManager.getAllSharedBundleInfo<sup>10+</sup> 4003 4004getAllSharedBundleInfo(callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void 4005 4006获取所有的共享包信息,使用callback异步回调。 4007 4008**系统接口:** 此接口为系统接口。 4009 4010**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4011 4012**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4013 4014**参数:** 4015 4016| 参数名 | 类型 | 必填 | 说明 | 4017| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4018| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo-sys.md)\>\> | 是 | 回调函数,当获取成功时,err为null,data为获所有的共享包信息。 | 4019 4020**错误码:** 4021 4022以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4023 4024| 错误码ID | 错误信息 | 4025| -------- | ------------------------------------- | 4026| 201 | Permission denied. | 4027| 202 | Permission denied, non-system app called system api. | 4028 4029**示例:** 4030 4031```ts 4032import { bundleManager } from '@kit.AbilityKit'; 4033import { BusinessError } from '@kit.BasicServicesKit'; 4034import { hilog } from '@kit.PerformanceAnalysisKit'; 4035 4036try { 4037 bundleManager.getAllSharedBundleInfo((err, data) => { 4038 if (err) { 4039 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', err.message); 4040 } else { 4041 hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully: %{public}s', JSON.stringify(data)); 4042 } 4043 }); 4044} catch (err) { 4045 let message = (err as BusinessError).message; 4046 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', message); 4047} 4048``` 4049 4050## bundleManager.getAllSharedBundleInfo<sup>10+</sup> 4051 4052getAllSharedBundleInfo(): Promise\<Array\<SharedBundleInfo\>\> 4053 4054获取所有的共享包信息,使用Promise异步回调。 4055 4056**系统接口:** 此接口为系统接口 4057 4058**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4059 4060**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4061 4062**返回值:** 4063 4064| 类型 | 说明 | 4065| ------------------------------------------------------------ | ----------------------------------- | 4066| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo-sys.md)\>\> | Promise对象,返回所有的共享包信息。 | 4067 4068**错误码:** 4069 4070以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4071 4072| 错误码ID | 错误信息 | 4073| -------- | ------------------------------------- | 4074| 201 | Permission denied. | 4075| 202 | Permission denied, non-system app called system api. | 4076 4077**示例:** 4078 4079```ts 4080import { bundleManager } from '@kit.AbilityKit'; 4081import { BusinessError } from '@kit.BasicServicesKit'; 4082import { hilog } from '@kit.PerformanceAnalysisKit'; 4083 4084try { 4085 bundleManager.getAllSharedBundleInfo().then((data) => { 4086 hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 4087 }).catch((err: BusinessError) => { 4088 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', err.message); 4089 }); 4090} catch (err) { 4091 let message = (err as BusinessError).message; 4092 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', message); 4093} 4094``` 4095 4096## bundleManager.getAppProvisionInfo<sup>10+</sup> 4097 4098getAppProvisionInfo(bundleName: string, callback: AsyncCallback\<AppProvisionInfo\>): void 4099 4100获取指定bundleName的provision配置文件信息,使用callback异步回调。 4101 4102**系统接口:** 此接口为系统接口。 4103 4104**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4105 4106**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4107 4108**参数:** 4109 4110| 参数名 | 类型 | 必填 | 说明 | 4111| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4112| bundleName | string | 是 | 指定应用的bundleName。 | 4113| callback | AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo-sys.md)\> | 是 | 回调函数,当获取成功时,err为null,data为指定bundleName的provision配置文件信息。 | 4114 4115**错误码:** 4116 4117以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4118 4119| 错误码ID | 错误信息 | 4120| -------- | -------------------------------------- | 4121| 201 | Permission denied. | 4122| 202 | Permission denied, non-system app called system api. | 4123| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter bundleName is empty. | 4124| 17700001 | The specified bundleName is not found. | 4125 4126**示例:** 4127 4128```ts 4129import { bundleManager } from '@kit.AbilityKit'; 4130import { BusinessError } from '@kit.BasicServicesKit'; 4131import { hilog } from '@kit.PerformanceAnalysisKit'; 4132let bundleName = "com.ohos.myapplication"; 4133 4134try { 4135 bundleManager.getAppProvisionInfo(bundleName, (err, data) => { 4136 if (err) { 4137 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message); 4138 } else { 4139 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data)); 4140 } 4141 }); 4142} catch (err) { 4143 let message = (err as BusinessError).message; 4144 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message); 4145} 4146``` 4147 4148## bundleManager.getAppProvisionInfo<sup>10+</sup> 4149 4150getAppProvisionInfo(bundleName: string, userId: number, callback: AsyncCallback\<AppProvisionInfo\>): void 4151 4152获取指定bundleName和userId的provision配置文件信息,使用callback异步回调。 4153 4154**系统接口:** 此接口为系统接口。 4155 4156**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4157 4158**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4159 4160**参数:** 4161 4162| 参数名 | 类型 | 必填 | 说明 | 4163| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4164| bundleName | string | 是 | 指定应用的bundleName。 | 4165| userId | number | 是 | 指定用户ID, 可以通过接口[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | 4166| callback | AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo-sys.md)\> | 是 | 回调函数,当获取成功时,err为null,data为指定bundleName的provision配置文件信息。 | 4167 4168 4169**错误码:** 4170 4171以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4172 4173| 错误码ID | 错误信息 | 4174| -------- | -------------------------------------- | 4175| 201 | Permission denied. | 4176| 202 | Permission denied, non-system app called system api. | 4177| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter bundleName is empty. | 4178| 17700001 | The specified bundleName is not found. | 4179| 17700004 | The specified user ID is not found. | 4180 4181**示例:** 4182 4183```ts 4184import { bundleManager } from '@kit.AbilityKit'; 4185import { BusinessError } from '@kit.BasicServicesKit'; 4186import { hilog } from '@kit.PerformanceAnalysisKit'; 4187let bundleName = "com.ohos.myapplication"; 4188let userId = 100; 4189 4190try { 4191 bundleManager.getAppProvisionInfo(bundleName, userId, (err, data) => { 4192 if (err) { 4193 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message); 4194 } else { 4195 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data)); 4196 } 4197 }); 4198} catch (err) { 4199 let message = (err as BusinessError).message; 4200 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message); 4201} 4202``` 4203 4204## bundleManager.getAppProvisionInfo<sup>10+</sup> 4205 4206getAppProvisionInfo(bundleName: string, userId?: number): Promise\<AppProvisionInfo\> 4207 4208根据bundleName和userId获取应用的provision配置文件信息,使用Promise异步回调。 4209 4210**系统接口:** 此接口为系统接口 4211 4212**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4213 4214**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4215 4216**参数:** 4217 4218| 参数名 | 类型 | 必填 | 说明 | 4219| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4220| bundleName | string | 是 | 指定的bundleName。 | 4221| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | 4222 4223 4224**返回值:** 4225 4226| 类型 | 说明 | 4227| ------------------------------------------------------------ | ----------------------------------- | 4228| Promise\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo-sys.md)\> | Promise对象,返回应用的provision配置文件信息。 | 4229 4230**错误码:** 4231 4232以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4233 4234| 错误码ID | 错误信息 | 4235| -------- | -------------------------------------- | 4236| 201 | Permission denied. | 4237| 202 | Permission denied, non-system app called system api. | 4238| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter bundleName is empty. | 4239| 17700001 | The specified bundleName is not found. | 4240| 17700004 | The specified user ID is not found. | 4241 4242**示例:** 4243 4244```ts 4245import { bundleManager } from '@kit.AbilityKit'; 4246import { BusinessError } from '@kit.BasicServicesKit'; 4247import { hilog } from '@kit.PerformanceAnalysisKit'; 4248let bundleName = "com.ohos.myapplication"; 4249let userId = 100; 4250 4251try { 4252 bundleManager.getAppProvisionInfo(bundleName).then((data) => { 4253 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data)); 4254 }).catch((err: BusinessError) => { 4255 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message); 4256 }); 4257} catch (err) { 4258 let message = (err as BusinessError).message; 4259 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message); 4260} 4261 4262try { 4263 bundleManager.getAppProvisionInfo(bundleName, userId).then((data) => { 4264 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data)); 4265 }).catch((err: BusinessError) => { 4266 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message); 4267 }); 4268} catch (err) { 4269 let message = (err as BusinessError).message; 4270 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message); 4271} 4272``` 4273 4274## bundleManager.getAppProvisionInfoSync<sup>10+</sup> 4275 4276getAppProvisionInfoSync(bundleName: string, userId?: number): AppProvisionInfo 4277 4278以同步方法根据bundleName和userId获取应用的provision配置文件信息并返回结果。 4279 4280**系统接口:** 此接口为系统接口 4281 4282**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4283 4284**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4285 4286**参数:** 4287 4288| 参数名 | 类型 | 必填 | 说明 | 4289| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4290| bundleName | string | 是 | 指定的bundleName。 | 4291| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0,可以通过接口[getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取当前设备上的用户ID。 | 4292 4293 4294**返回值:** 4295 4296| 类型 | 说明 | 4297| ------------------------------------------------------------ | ----------------------------------- | 4298| [AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo-sys.md) | AppProvisionInfo对象,返回应用的provision配置文件信息。 | 4299 4300**错误码:** 4301 4302以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4303 4304| 错误码ID | 错误信息 | 4305| -------- | -------------------------------------- | 4306| 201 | Permission denied. | 4307| 202 | Permission denied, non-system app called system api. | 4308| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter bundleName is empty. | 4309| 17700001 | The specified bundleName is not found. | 4310| 17700004 | The specified user ID is not found. | 4311 4312**示例:** 4313 4314```ts 4315import { bundleManager } from '@kit.AbilityKit'; 4316import { BusinessError } from '@kit.BasicServicesKit'; 4317import { hilog } from '@kit.PerformanceAnalysisKit'; 4318let bundleName = "com.ohos.myapplication"; 4319let userId = 100; 4320 4321try { 4322 let data = bundleManager.getAppProvisionInfoSync(bundleName); 4323 hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4324} catch (err) { 4325 let message = (err as BusinessError).message; 4326 hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message); 4327} 4328 4329try { 4330 let data = bundleManager.getAppProvisionInfoSync(bundleName, userId); 4331 hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4332} catch (err) { 4333 let message = (err as BusinessError).message; 4334 hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message); 4335} 4336``` 4337 4338## bundleManager.getSpecifiedDistributionType<sup>10+</sup> 4339getSpecifiedDistributionType(bundleName: string): string 4340 4341以同步的方法查询指定bundleName的[分发类型](../../security/app-provision-structure.md),该返回值是在调用install接口时传入的[InstallParam](./js-apis-installer-sys.md#installparam)中的specifiedDistributionType字段。 4342 4343**系统接口:** 此接口为系统接口。 4344 4345**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4346 4347**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4348 4349**参数:** 4350 4351| 参数名 | 类型 | 必填 | 说明 | 4352| -------------- | ----------------------------------- | ---- | ---------------------------- | 4353| bundleName | string | 是 | 指定的bundleName。 | 4354 4355**返回值:** 4356 4357| 类型 | 说明 | 4358| ------------- | -------------------------------------- | 4359| string | 返回指定bundleName的[分发类型](../../security/app-provision-structure.md)。 | 4360 4361**错误码:** 4362 4363以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4364 4365| 错误码ID | 错误信息 | 4366| -------- | ------------------------------------------------------------ | 4367| 201 | Permission denied. | 4368| 202 | Permission denied, non-system app called system api. | 4369| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 4370| 17700001 | The specified bundleName is not found. | 4371 4372**示例:** 4373```ts 4374import { bundleManager } from '@kit.AbilityKit'; 4375import { BusinessError } from '@kit.BasicServicesKit'; 4376let bundleName = "com.example.myapplication"; 4377 4378try { 4379 let type = bundleManager.getSpecifiedDistributionType(bundleName); 4380 console.info('getSpecifiedDistributionType successfully, type:' + type); 4381} catch (error) { 4382 let message = (error as BusinessError).message; 4383 console.error('getSpecifiedDistributionType failed. Cause: ' + message); 4384} 4385``` 4386 4387 4388## bundleManager.getAdditionalInfo<sup>10+</sup> 4389 4390getAdditionalInfo(bundleName: string): string 4391 4392以同步接口查询指定bundleName的额外信息。该返回值是在调用install接口时传入的[InstallParam](./js-apis-installer-sys.md#installparam)中的additionalInfo字段。 4393 4394**系统接口:** 此接口为系统接口。 4395 4396**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4397 4398**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4399 4400**参数:** 4401 4402| 参数名 | 类型 | 必填 | 说明 | 4403| -------------- | ----------------------------------- | ---- | ---------------------------- | 4404| bundleName | string | 是 | 指定的bundleName。 | 4405 4406**返回值:** 4407 4408| 类型 | 说明 | 4409| ------------- | -------------------------------------- | 4410| string | 返回指定bundleName的额外信息。 | 4411 4412**错误码:** 4413 4414以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4415 4416| 错误码ID | 错误信息 | 4417| -------- | ------------------------------------------------------------ | 4418| 201 | Permission denied. | 4419| 202 | Permission denied, non-system app called system api. | 4420| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter bundleName is empty. | 4421| 17700001 | The specified bundleName is not found. | 4422 4423**示例:** 4424 4425```ts 4426import { bundleManager } from '@kit.AbilityKit'; 4427import { BusinessError } from '@kit.BasicServicesKit'; 4428let bundleName = "com.example.myapplication"; 4429 4430try { 4431 let info = bundleManager.getAdditionalInfo(bundleName); 4432 console.info('getAdditionalInfo successfully, additionInfo:' + info); 4433} catch (error) { 4434 let message = (error as BusinessError).message; 4435 console.error('getAdditionalInfo failed. Cause: ' + message); 4436} 4437``` 4438 4439## bundleManager.queryExtensionAbilityInfoSync<sup>11+</sup> 4440 4441queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: string, extensionAbilityFlags: number, userId?: number): Array\<ExtensionAbilityInfo> 4442 4443根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo,使用同步方式返回结果。 4444 4445**系统接口:** 此接口为系统接口。 4446 4447**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 4448 4449**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4450 4451**参数:** 4452 4453| 参数名 | 类型 | 必填 | 说明 | 4454| --------------------- | ------------------------------- | ---- | --------------------------------------------------------- | 4455| want | Want | 是 | 表示包含要查询的应用Bundle名称的Want。 | 4456| extensionAbilityType | string | 是 | 表示自定义extensionAbility的类型。 | 4457| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示返回的ExtensionInfo对象中需要包含的信息标志。 | 4458| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 4459 4460**返回值:** 4461 4462| 类型 | 说明 | 4463| ------------------------------------------------------------ | -------------------------------------- | 4464| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | 同步返回Array\<ExtensionAbilityInfo>。 | 4465 4466**错误码:** 4467 4468以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4469 4470| 错误码ID | 错误信息 | 4471| -------- | -------------------------------------------- | 4472| 201 | Permission denied. | 4473| 202 | Permission denied, non-system app called system api. | 4474| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. At least one parameter(action, entity, uri, type or linkFeature) is required for implicit query. | 4475| 17700001 | The specified bundleName is not found. | 4476| 17700003 | The specified extensionAbility is not found. | 4477| 17700004 | The specified userId is invalid. | 4478| 17700026 | The specified bundle is disabled. | 4479 4480**示例:** 4481 4482```ts 4483// 示例接口带userId参数查询 4484import { bundleManager } from '@kit.AbilityKit'; 4485import { hilog } from '@kit.PerformanceAnalysisKit'; 4486import { Want } from '@kit.AbilityKit'; 4487import { BusinessError } from '@kit.BasicServicesKit'; 4488 4489let extensionAbilityType = "form"; 4490let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4491let userId = 100; 4492let want: Want = { 4493 bundleName : "com.example.myapplication", 4494 abilityName : "EntryAbility" 4495}; 4496 4497try { 4498 let data = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId) 4499 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4500} catch (err) { 4501 let message = (err as BusinessError).message; 4502 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4503} 4504``` 4505 4506```ts 4507// 示例接口不带userId参数查询 4508import { bundleManager } from '@kit.AbilityKit'; 4509import { hilog } from '@kit.PerformanceAnalysisKit'; 4510import { Want } from '@kit.AbilityKit'; 4511import { BusinessError } from '@kit.BasicServicesKit'; 4512 4513let extensionAbilityType = "form"; 4514let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4515let want: Want = { 4516 bundleName : "com.example.myapplication", 4517 abilityName : "EntryAbility" 4518}; 4519 4520try { 4521 let data = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags); 4522 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4523} catch (err) { 4524 let message = (err as BusinessError).message; 4525 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4526} 4527``` 4528 4529## bundleManager.getJsonProfile<sup>11+</sup> 4530 4531getJsonProfile(profileType: ProfileType, bundleName: string, moduleName?: string, userId?: number): string 4532 4533以同步的方法根据给定的profileType、bundleName和moduleName查询相应配置文件的JSON字符串。 4534 4535获取调用方自己的配置文件时不需要权限。 4536 4537**系统接口:** 此接口为系统接口。 4538 4539**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 4540 4541**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4542 4543**参数:** 4544 4545| 参数名 | 类型 | 必填 | 说明 | 4546| --------------------- | ------------------------------- | ---- | --------------------------------------------------------- | 4547| profileType | [ProfileType](#profiletype11) | 是 | 表示要查询的配置文件类型。 | 4548| bundleName | string | 是 | 表示要查询应用程序的bundleName。 | 4549| moduleName | string | 否 | 表示要查询应用程序的module的名称,缺省时在入口模块中查找。 | 4550| userId<sup>12+</sup> | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 4551 4552**返回值:** 4553 4554| 类型 | 说明 | 4555| ------ | ------------------------ | 4556| string | 返回配置文件的JSON字符串。 | 4557 4558**错误码:** 4559 4560以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4561 4562| 错误码ID | 错误信息 | 4563| -------- | -------------------------------------------- | 4564| 201 | Permission denied. | 4565| 202 | Permission denied, non-system app called system api. | 4566| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 4567| 17700001 | The specified bundleName is not found. | 4568| 17700002 | The specified moduleName is not found. | 4569| 17700004 | The specified user ID is not found. | 4570| 17700024 | Failed to get the profile because the specified profile is not found in the HAP. | 4571| 17700026 | The specified bundle is disabled. | 4572 4573**示例:** 4574 4575```ts 4576import { bundleManager } from '@kit.AbilityKit'; 4577import { hilog } from '@kit.PerformanceAnalysisKit'; 4578import { BusinessError } from '@kit.BasicServicesKit'; 4579 4580let bundleName = 'com.example.myapplication'; 4581let moduleName = 'entry'; 4582let profileType = bundleManager.ProfileType.INTENT_PROFILE; 4583 4584try { 4585 let data = bundleManager.getJsonProfile(profileType, bundleName, moduleName) 4586 hilog.info(0x0000, 'testTag', 'getJsonProfile successfully. Data: %{public}s', data); 4587} catch (err) { 4588 let message = (err as BusinessError).message; 4589 hilog.error(0x0000, 'testTag', 'getJsonProfile failed: %{public}s', message); 4590} 4591``` 4592 4593## bundleManager.getRecoverableApplicationInfo<sup>11+</sup> 4594 4595getRecoverableApplicationInfo(callback: AsyncCallback\<Array\<RecoverableApplicationInfo\>\>): void 4596 4597获取所有可恢复的预置应用信息,使用callback异步回调。 4598 4599**系统接口:** 此接口为系统接口。 4600 4601**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4602 4603**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4604 4605**参数:** 4606 4607| 参数名 | 类型 | 必填 | 说明 | 4608| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4609| callback | AsyncCallback\<Array\<[RecoverableApplicationInfo](js-apis-bundleManager-recoverableApplicationInfo-sys.md)\>\> | 是 | 回调函数,当获取成功时,err为null,data为获取到的所有可恢复的预置应用信息。 | 4610 4611**错误码:** 4612 4613以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4614 4615| 错误码ID | 错误信息 | 4616| -------- | -------------------------------------------- | 4617| 201 | Permission denied. | 4618| 202 | Permission denied, non-system app called system api. | 4619 4620**示例:** 4621 4622```ts 4623import { bundleManager } from '@kit.AbilityKit'; 4624import { BusinessError } from '@kit.BasicServicesKit'; 4625import { hilog } from '@kit.PerformanceAnalysisKit'; 4626 4627try { 4628 bundleManager.getRecoverableApplicationInfo((err, data) => { 4629 if (err) { 4630 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', err.message); 4631 } else { 4632 hilog.info(0x0000, 'testTag', 'getRecoverableApplicationInfo successfully: %{public}s', JSON.stringify(data)); 4633 } 4634 }); 4635} catch (err) { 4636 let message = (err as BusinessError).message; 4637 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', message); 4638} 4639``` 4640 4641## bundleManager.getRecoverableApplicationInfo<sup>11+</sup> 4642 4643getRecoverableApplicationInfo(): Promise\<Array\<RecoverableApplicationInfo\>\> 4644 4645获取所有可恢复的预置应用信息,使用Promise异步回调。 4646 4647**系统接口:** 此接口为系统接口。 4648 4649**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4650 4651**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4652 4653**返回值:** 4654 4655| 类型 | 说明 | 4656| ------------------------------------------------------------ | ----------------------------------- | 4657| Promise\<Array\<[RecoverableApplicationInfo](js-apis-bundleManager-recoverableApplicationInfo-sys.md)\>\> | Promise对象,返回所有可恢复的预置应用信息。 | 4658 4659**错误码:** 4660 4661以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4662 4663| 错误码ID | 错误信息 | 4664| -------- | -------------------------------------------- | 4665| 201 | Permission denied. | 4666| 202 | Permission denied, non-system app called system api. | 4667 4668**示例:** 4669 4670```ts 4671import { bundleManager } from '@kit.AbilityKit'; 4672import { BusinessError } from '@kit.BasicServicesKit'; 4673import { hilog } from '@kit.PerformanceAnalysisKit'; 4674 4675try { 4676 bundleManager.getRecoverableApplicationInfo().then((data) => { 4677 hilog.info(0x0000, 'testTag', 'getRecoverableApplicationInfo successfully: %{public}s', JSON.stringify(data)); 4678 }).catch((err: BusinessError) => { 4679 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', err.message); 4680 }); 4681} catch (err) { 4682 let message = (err as BusinessError).message; 4683 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', message); 4684} 4685``` 4686 4687## bundleManager.setAdditionalInfo<sup>11+</sup> 4688 4689setAdditionalInfo(bundleName: string, additionalInfo: string): void 4690 4691设置指定应用的额外信息。此接口仅供应用市场调用。 4692 4693**系统接口:** 此接口为系统接口。 4694 4695**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4696 4697**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4698 4699**参数:** 4700 4701| 参数名 | 类型 | 必填 | 说明 | 4702| --------------------- | ------------------------------- | ---- | -------------------------------------------------- | 4703| bundleName | string | 是 | 指定应用的包名。 | 4704| additionalInfo | string | 是 | 需要设置的应用的额外信息。 | 4705 4706**错误码:** 4707 4708以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4709 4710| 错误码ID | 错误信息 | 4711| -------- | ---------------------------------------------------------- | 4712| 201 | Permission denied. | 4713| 202 | Permission denied, non-system app called system api. | 4714| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter bundleName is empty. | 4715| 17700001 | The specified bundleName is not found. | 4716| 17700053 | The caller is not AppGallery. | 4717 4718**示例:** 4719 4720```ts 4721import { bundleManager } from '@kit.AbilityKit'; 4722import { BusinessError } from '@kit.BasicServicesKit'; 4723import { hilog } from '@kit.PerformanceAnalysisKit'; 4724 4725let bundleName = "com.example.myapplication"; 4726let additionalInfo = "xxxxxxxxx,formUpdateLevel:4"; 4727 4728try { 4729 bundleManager.setAdditionalInfo(bundleName, additionalInfo); 4730 hilog.info(0x0000, 'testTag', 'setAdditionalInfo successfully.'); 4731} catch (err) { 4732 let message = (err as BusinessError).message; 4733 hilog.error(0x0000, 'testTag', 'setAdditionalInfo failed. Cause: %{public}s', message); 4734} 4735``` 4736 4737## bundleManager.getAllPreinstalledApplicationInfo<sup>12+</sup> 4738 4739getAllPreinstalledApplicationInfo(): Promise\<Array\<PreinstalledApplicationInfo\>\> 4740 4741获取所有预置应用信息,使用promise异步回调。 4742 4743**系统接口:** 此接口为系统接口。 4744 4745**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4746 4747**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4748 4749**返回值:** 4750 4751| 类型 | 说明 | 4752| ------------------------------------------------------------ | ----------------------------------- | 4753| Promise<Array\<[PreinstalledApplicationInfo](js-apis-bundleManager-ApplicationInfo-sys.md)>> | Promise对象,返回Array\<PreinstalledApplicationInfo>。 | 4754 4755**错误码:** 4756 4757以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4758 4759| 错误码ID | 错误信息 | 4760| -------- | ---------------------------------------------------------- | 4761| 201 | Permission denied. | 4762| 202 | Permission denied, non-system app called system api. | 4763 4764**示例:** 4765 4766```ts 4767import { bundleManager } from '@kit.AbilityKit'; 4768import { BusinessError } from '@kit.BasicServicesKit'; 4769import { hilog } from '@kit.PerformanceAnalysisKit'; 4770 4771try { 4772 let data = bundleManager.getAllPreinstalledApplicationInfo(); 4773 hilog.info(0x0000, 'testTag', 'getAllPreinstalledApplicationInfo success, Data: %{public}s', JSON.stringify(data)); 4774} catch (err) { 4775 let message = (err as BusinessError).message; 4776 hilog.error(0x0000, 'testTag', 'getAllPreinstalledApplicationInfo failed: %{public}s', message); 4777} 4778``` 4779 4780## bundleManager.queryExtensionAbilityInfoSync<sup>11+</sup> 4781 4782queryExtensionAbilityInfoSync(extensionAbilityType: string, extensionAbilityFlags: number, userId?: number): Array\<ExtensionAbilityInfo> 4783 4784根据给定的extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo。 4785 4786**系统接口:** 此接口为系统接口。 4787 4788**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 4789 4790**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4791 4792**参数:** 4793 4794| 参数名 | 类型 | 必填 | 说明 | 4795| --------------------- | ------------------------------- | ---- | --------------------------------------------------------- | 4796| extensionAbilityType | string | 是 | 表示自定义extensionAbility的类型。 | 4797| extensionAbilityFlags | [number](#extensionabilityflag) | 是 | 表示返回的ExtensionInfo对象中需要包含的信息标志。 | 4798| userId | number | 否 | 表示用户ID,默认值:调用方所在用户ID。取值范围:大于等于0。 | 4799 4800**返回值:** 4801 4802| 类型 | 说明 | 4803| ------------------------------------------------------------ | -------------------------------------- | 4804| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | 同步返回Array\<ExtensionAbilityInfo>。 | 4805 4806**错误码:** 4807 4808以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4809 4810| 错误码ID | 错误信息 | 4811| -------- | -------------------------------------------- | 4812| 201 | Permission denied. | 4813| 202 | Permission denied, non-system app called system api. | 4814| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter extensionAbilityType is empty. | 4815| 17700003 | The specified extensionAbility is not found. | 4816| 17700004 | The specified userId is invalid. | 4817 4818**示例:** 4819 4820```ts 4821// 示例接口带userId参数查询 4822import { bundleManager } from '@kit.AbilityKit'; 4823import { hilog } from '@kit.PerformanceAnalysisKit'; 4824import { BusinessError } from '@kit.BasicServicesKit'; 4825 4826let extensionAbilityType = "form"; 4827let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4828let userId = 100; 4829 4830try { 4831 let data = bundleManager.queryExtensionAbilityInfoSync(extensionAbilityType, extensionFlags, userId) 4832 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4833} catch (err) { 4834 let message = (err as BusinessError).message; 4835 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4836} 4837``` 4838 4839```ts 4840// 示例接口不带userId参数查询 4841import { bundleManager } from '@kit.AbilityKit'; 4842import { hilog } from '@kit.PerformanceAnalysisKit'; 4843import { BusinessError } from '@kit.BasicServicesKit'; 4844 4845let extensionAbilityType = "form"; 4846let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4847 4848try { 4849 let data = bundleManager.queryExtensionAbilityInfoSync(extensionAbilityType, extensionFlags); 4850 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4851} catch (err) { 4852 let message = (err as BusinessError).message; 4853 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4854} 4855``` 4856 4857## bundleManager.getAllBundleInfoByDeveloperId<sup>12+</sup> 4858 4859getAllBundleInfoByDeveloperId(developerId: string): Array\<BundleInfo> 4860 4861根据给定的developerId获取当前用户下的包信息列表。 4862 4863**系统接口:** 此接口为系统接口。 4864 4865**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4866 4867**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4868 4869**参数:** 4870 4871| 参数名 | 类型 | 必填 | 说明 | 4872| --------------------- | ---------| ---- | --------------------- | 4873| developerId | string | 是 | 表示应用的开发者ID。 | 4874 4875**返回值:** 4876 4877| 类型 | 说明 | 4878| ------------------------------------------------------------ | -------------------------------------- | 4879| Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 同步返回Array\<BundleInfo>。 | 4880 4881**错误码:** 4882 4883以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4884 4885| 错误码ID | 错误信息 | 4886| -------- | -------------------------------------------- | 4887| 201 | Permission denied. | 4888| 202 | Permission denied, non-system app called system api. | 4889| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter developerId is empty. | 4890| 17700059 | The specified developerId is invalid. | 4891 4892**示例:** 4893 4894```ts 4895import { bundleManager } from '@kit.AbilityKit'; 4896import { hilog } from '@kit.PerformanceAnalysisKit'; 4897import { BusinessError } from '@kit.BasicServicesKit'; 4898 4899let developerId = "123456.789"; 4900 4901try { 4902 let data = bundleManager.getAllBundleInfoByDeveloperId(developerId); 4903 hilog.info(0x0000, 'testTag', 'getAllBundleInfoByDeveloperId successfully. Data: %{public}s', JSON.stringify(data)); 4904} catch (err) { 4905 let message = (err as BusinessError).message; 4906 hilog.error(0x0000, 'testTag', 'getAllBundleInfoByDeveloperId failed: %{public}s', message); 4907} 4908``` 4909 4910## bundleManager.getDeveloperIds<sup>12+</sup> 4911 4912getDeveloperIds(appDistributionType?: number): Array\<String> 4913 4914根据给定的应用[分发类型](#appdistributiontype12)获取当前用户下的所有的开发者ID列表。 4915 4916**系统接口:** 此接口为系统接口。 4917 4918**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4919 4920**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4921 4922**参数:** 4923 4924| 参数名 | 类型 | 必填 | 说明 | 4925| --------------------- | ---------| ---- | --------------------- | 4926| [appDistributionType](#appdistributiontype12) | number | 否 | 表示应用的分发类型,当该参数缺省时,会返回所有应用的开发者ID列表。 | 4927 4928**返回值:** 4929 4930| 类型 | 说明 | 4931| ------------------------------------------------------------ | -------------------------------------- | 4932| Array\<String> | 同步返回Array\<String>。 | 4933 4934**错误码:** 4935 4936以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 4937 4938| 错误码ID | 错误信息 | 4939| -------- | -------------------------------------------- | 4940| 201 | Permission denied. | 4941| 202 | Permission denied, non-system app called system api. | 4942| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 4943 4944**示例:** 4945 4946```ts 4947import { bundleManager } from '@kit.AbilityKit'; 4948import { hilog } from '@kit.PerformanceAnalysisKit'; 4949import { BusinessError } from '@kit.BasicServicesKit'; 4950 4951let appDistributionType = bundleManager.AppDistributionType.ENTERPRISE; 4952 4953try { 4954 let data = bundleManager.getDeveloperIds(appDistributionType); 4955 hilog.info(0x0000, 'testTag', 'getDeveloperIds successfully. Data: %{public}s', JSON.stringify(data)); 4956} catch (err) { 4957 let message = (err as BusinessError).message; 4958 hilog.error(0x0000, 'testTag', 'getDeveloperIds failed: %{public}s', message); 4959} 4960``` 4961 4962## bundleManager.switchUninstallState<sup>12+</sup> 4963 4964switchUninstallState(bundleName: string, state: boolean): void 4965 4966切换指定应用的可卸载状态,此接口与EDM应用拦截管控机制不互相影响。 4967 4968**系统接口:** 此接口为系统接口。 4969 4970**需要权限:** ohos.permission.CHANGE_BUNDLE_UNINSTALL_STATE 4971 4972**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 4973 4974**参数:** 4975 4976| 参数名 | 类型 | 必填 | 说明 | 4977| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4978| bundleName | string | 是 | 表示指定应用的bundleName。 | 4979| state | boolean | 是 | 表示应用的可卸载状态,值为true表示应用可以被卸载,值为false表示应用不可以被卸载。 | 4980 4981**错误码:** 4982 4983以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 4984 4985| 错误码ID | 错误信息 | 4986| -------- | -------------------------------------- | 4987| 201 | Permission denied. | 4988| 202 | Permission denied, non-system app called system api. | 4989| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 4990| 17700001 | The specified bundleName is not found. | 4991| 17700060 | The specified application cannot be uninstalled. | 4992 4993**示例:** 4994 4995```ts 4996import { bundleManager } from '@kit.AbilityKit'; 4997import { hilog } from '@kit.PerformanceAnalysisKit'; 4998import { BusinessError } from '@kit.BasicServicesKit'; 4999 5000try { 5001 bundleManager.switchUninstallState('com.example.myapplication', false); 5002} catch (err) { 5003 let message = (err as BusinessError).message; 5004 hilog.error(0x0000, 'testTag', 'switchUninstallState failed: %{public}s', message); 5005} 5006``` 5007 5008## bundleManager.getExtResource<sup>12+</sup> 5009 5010getExtResource(bundleName: string): Promise\<Array\<string>>; 5011 5012根据给定的bundleName获得扩展资源对应的moduleNames。使用Promise异步回调。 5013 5014**系统接口:** 此接口为系统接口。 5015 5016**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 5017 5018**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5019 5020**参数:** 5021 5022| 参数名 | 类型 | 必填 | 说明 | 5023| ----------- | ------ | ---- | ---------------------------- | 5024| bundleName | string | 是 | 要查询扩展资源的应用名称。 | 5025 5026**返回值:** 5027 5028| 类型 | 说明 | 5029| ----------------------------------------------------------- | --------------------------- | 5030| Promise\<Array\<string>> | 以Promise方式返回接口运行结果及扩展资源对应的moduleNames。 | 5031 5032**错误码:** 5033 5034以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5035 5036| 错误码ID | 错误信息 | 5037| -------- | --------------------------------------| 5038| 201 | Permission denied. | 5039| 202 | Permission denied, non-system app called system api. | 5040| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5041| 17700001 | The specified bundleName is not found. | 5042| 17700303 | Failed to obtain extended resources. | 5043 5044**示例:** 5045 5046```ts 5047import { bundleManager } from '@kit.AbilityKit'; 5048import { BusinessError } from '@kit.BasicServicesKit'; 5049import { hilog } from '@kit.PerformanceAnalysisKit'; 5050let bundleName : string = 'com.ohos.demo'; 5051 5052try { 5053 bundleManager.getExtResource(bundleName).then((modules : Array<string>) => { 5054 for (let i = 0; i < modules.length; i++) { 5055 hilog.info(0x0000, 'testTag', 'getExtResource item: %s', modules[i]); 5056 } 5057 }).catch((err: BusinessError) => { 5058 hilog.error(0x0000, 'testTag', 'getExtResource failed. Cause: %{public}s', err.message); 5059 }); 5060} catch (err) { 5061 let message = (err as BusinessError).message; 5062 hilog.error(0x0000, 'testTag', 'getExtResource failed. Cause: %{public}s', message); 5063} 5064``` 5065 5066## bundleManager.enableDynamicIcon<sup>12+</sup> 5067 5068enableDynamicIcon(bundleName: string, moduleName: string): Promise\<void>; 5069 5070根据给定的bundleName、moduleName使能动态图标。使用Promise异步回调。 5071 5072**系统接口:** 此接口为系统接口。 5073 5074**需要权限:** ohos.permission.ACCESS_DYNAMIC_ICON 5075 5076**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5077 5078**参数:** 5079 5080| 参数名 | 类型 | 必填 | 说明 | 5081| ----------- | ------ | ---- | ---------------------------- | 5082| bundleName | string | 是 | 要使能动态图标的应用名称。 | 5083| moduleName | string | 是 | 要使能动态图标的模块名称。 | 5084 5085**返回值:** 5086 5087| 类型 | 说明 | 5088| ----------------------------------------------------------- | --------------------------- | 5089| Promise\<void> | 无返回结果的Promise对象。 | 5090 5091**错误码:** 5092 5093以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5094 5095| 错误码ID | 错误信息 | 5096| -------- | --------------------------------------| 5097| 201 | Permission denied. | 5098| 202 | Permission denied, non-system app called system api. | 5099| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5100| 17700001 | The specified bundleName is not found. | 5101| 17700002 | The specified moduleName is not found. | 5102| 17700304 | Failed to enable the dynamic icon. | 5103 5104**示例:** 5105 5106```ts 5107import { bundleManager } from '@kit.AbilityKit'; 5108import { BusinessError } from '@kit.BasicServicesKit'; 5109import { hilog } from '@kit.PerformanceAnalysisKit'; 5110let bundleName : string = 'com.ohos.demo'; 5111let moduleName : string = 'moduleTest'; 5112 5113try { 5114 bundleManager.enableDynamicIcon(bundleName, moduleName).then((data) => { 5115 hilog.info(0x0000, 'testTag', 'enableDynamicIcon successfully'); 5116 }).catch((err: BusinessError) => { 5117 hilog.error(0x0000, 'testTag', 'enableDynamicIcon failed. Cause: %{public}s', err.message); 5118 }); 5119} catch (err) { 5120 let message = (err as BusinessError).message; 5121 hilog.error(0x0000, 'testTag', 'enableDynamicIcon failed. Cause: %{public}s', message); 5122} 5123``` 5124 5125## bundleManager.disableDynamicIcon<sup>12+</sup> 5126 5127disableDynamicIcon(bundleName: string): Promise\<void>; 5128 5129根据给定的bundleName禁用动态图标。使用Promise异步回调。 5130 5131**系统接口:** 此接口为系统接口。 5132 5133**需要权限:** ohos.permission.ACCESS_DYNAMIC_ICON 5134 5135**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5136 5137**参数:** 5138 5139| 参数名 | 类型 | 必填 | 说明 | 5140| ----------- | ------ | ---- | ---------------------------- | 5141| bundleName | string | 是 | 要禁用动态图标的应用名称。 | 5142 5143**返回值:** 5144 5145| 类型 | 说明 | 5146| ----------------------------------------------------------- | --------------------------- | 5147| Promise\<void> | 无返回结果的Promise对象。 | 5148 5149**错误码:** 5150 5151以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5152 5153| 错误码ID | 错误信息 | 5154| -------- | --------------------------------------| 5155| 201 | Permission denied. | 5156| 202 | Permission denied, non-system app called system api. | 5157| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5158| 17700001 | The specified bundleName is not found. | 5159| 17700305 | Failed to disable the dynamic icon. | 5160 5161**示例:** 5162 5163```ts 5164import { bundleManager } from '@kit.AbilityKit'; 5165import { BusinessError } from '@kit.BasicServicesKit'; 5166import { hilog } from '@kit.PerformanceAnalysisKit'; 5167let bundleName : string = 'com.ohos.demo'; 5168 5169try { 5170 bundleManager.disableDynamicIcon(bundleName).then((data) => { 5171 hilog.info(0x0000, 'testTag', 'disableDynamicIcon successfully'); 5172 }).catch((err: BusinessError) => { 5173 hilog.error(0x0000, 'testTag', 'disableDynamicIcon failed. Cause: %{public}s', err.message); 5174 }); 5175} catch (err) { 5176 let message = (err as BusinessError).message; 5177 hilog.error(0x0000, 'testTag', 'disableDynamicIcon failed. Cause: %{public}s', message); 5178} 5179``` 5180 5181## bundleManager.getDynamicIcon<sup>12+</sup> 5182 5183getDynamicIcon(bundleName: string): Promise\<string>; 5184 5185根据给定的bundleName获得动态图标对应的moduleName。使用Promise异步回调。 5186 5187**系统接口:** 此接口为系统接口。 5188 5189**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 5190 5191**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5192 5193**参数:** 5194 5195| 参数名 | 类型 | 必填 | 说明 | 5196| ----------- | ------ | ---- | ---------------------------- | 5197| bundleName | string | 是 | 要查询扩展资源的应用名称。 | 5198 5199**返回值:** 5200 5201| 类型 | 说明 | 5202| ----------------------------------------------------------- | --------------------------- | 5203| Promise\<string> | 以Promise方式返回接口运行结果及动态图标对应的moduleName。 | 5204 5205**错误码:** 5206 5207以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5208 5209| 错误码ID | 错误信息 | 5210| -------- | --------------------------------------| 5211| 201 | Permission denied. | 5212| 202 | Permission denied, non-system app called system api. | 5213| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5214| 17700001 | The specified bundleName is not found. | 5215| 17700306 | Failed to obtain the dynamic icon. | 5216 5217**示例:** 5218 5219```ts 5220import { bundleManager } from '@kit.AbilityKit'; 5221import { BusinessError } from '@kit.BasicServicesKit'; 5222import { hilog } from '@kit.PerformanceAnalysisKit'; 5223let bundleName : string = 'com.ohos.demo'; 5224 5225try { 5226 bundleManager.getDynamicIcon(bundleName).then((data) => { 5227 hilog.info(0x0000, 'testTag', 'getDynamicIcon successfully %s', JSON.stringify(data)); 5228 }).catch((err: BusinessError) => { 5229 hilog.error(0x0000, 'testTag', 'getDynamicIcon failed. Cause: %{public}s', err.message); 5230 }); 5231} catch (err) { 5232 let message = (err as BusinessError).message; 5233 hilog.error(0x0000, 'testTag', 'getDynamicIcon failed. Cause: %{public}s', message); 5234} 5235``` 5236 5237## bundleManager.getAppCloneIdentity<sup>14+</sup> 5238 5239getAppCloneIdentity(uid: number): Promise\<AppCloneIdentity>; 5240 5241根据uid查询分身应用的bundleName和appIndex。使用Promise异步回调。 5242 5243**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 5244 5245**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5246 5247**参数:** 5248 5249| 参数名 | 类型 | 必填 | 说明 | 5250| ---------- | ------ | ---- | ---------------------------| 5251| uid | number | 是 | 表示应用程序的UID。 | 5252 5253**返回值:** 5254 5255| 类型 | 说明 | 5256| ----------------------------------------------------------- | --------------------------- | 5257| Promise\<AppCloneIdentity> | 以Promise方式返回\<AppCloneIdentity>。 | 5258 5259**错误码:** 5260 5261以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5262 5263| 错误码ID | 错误信息 | 5264| -------- | --------------------------------------| 5265| 201 | Permission denied. | 5266| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5267| 17700021 | The uid is not found. | 5268 5269**示例:** 5270 5271```ts 5272import { bundleManager } from '@kit.AbilityKit'; 5273import { BusinessError } from '@kit.BasicServicesKit'; 5274import { hilog } from '@kit.PerformanceAnalysisKit'; 5275let uid = 20010005; 5276 5277try { 5278 bundleManager.getAppCloneIdentity(uid).then((res: bundleManager.AppCloneIdentity) => { 5279 hilog.info(0x0000, 'testTag', 'getAppCloneIdentity res = %{public}s', JSON.stringify(res)); 5280 }).catch((err: BusinessError) => { 5281 hilog.error(0x0000, 'testTag', 'getAppCloneIdentity failed. Cause: %{public}s', err.message); 5282 }); 5283} catch (err) { 5284 let message = (err as BusinessError).message; 5285 hilog.error(0x0000, 'testTag', 'getAppCloneIdentity failed. Cause: %{public}s', message); 5286} 5287``` 5288 5289## bundleManager.getAppCloneBundleInfo<sup>12+</sup> 5290 5291getAppCloneBundleInfo(bundleName: string, appIndex: number, bundleFlags: number, userId?: number): Promise\<BundleInfo>; 5292 5293根据bundleName、分身索引、[bundleFlags](js-apis-bundleManager.md#bundleflag)以及用户ID查询主应用或分身应用的BundleInfo。使用Promise异步回调。 5294 5295**系统接口:** 此接口为系统接口。 5296 5297**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 5298 5299**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5300 5301**参数:** 5302 5303| 参数名 | 类型 | 必填 | 说明 | 5304| ---------- | ------ | ---- | ---------------------------| 5305| bundleName | number | 是 | 表示要查询的应用Bundle名称。 | 5306| appIndex | number | 是 | 表示要查询的分身应用索引。<br>appIndex为0时,表示查询主应用信息。appIndex大于0时,表示查询指定分身应用信息。 | 5307| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 5308| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 5309 5310**返回值:** 5311 5312| 类型 | 说明 | 5313| ----------------------------------------------------------- | --------------------------- | 5314| Promise\<BundleInfo> | 以Promise方式返回应用包信息。 | 5315 5316**错误码:** 5317 5318以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5319 5320| 错误码ID | 错误信息 | 5321| -------- | --------------------------------------| 5322| 201 | Permission denied. | 5323| 202 | Permission denied, non-system app called system api. | 5324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5325| 17700001 | The specified bundleName is not found. | 5326| 17700004 | The specified userId is invalid. | 5327| 17700026 | The specified bundle is disabled. | 5328| 17700061 | The appIndex is invalid. | 5329 5330**示例:** 5331 5332```ts 5333import { bundleManager } from '@kit.AbilityKit'; 5334import { BusinessError } from '@kit.BasicServicesKit'; 5335import { hilog } from '@kit.PerformanceAnalysisKit'; 5336let bundleName = 'com.example.myapplication'; 5337let appIndex = 1; 5338let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; 5339 5340try { 5341 bundleManager.getAppCloneBundleInfo(bundleName, appIndex, bundleFlags).then((res: bundleManager.BundleInfo) => { 5342 hilog.info(0x0000, 'testTag', 'getAppCloneBundleInfo res: BundleInfo = %{public}s', JSON.stringify(res)); 5343 }).catch((err: BusinessError) => { 5344 hilog.error(0x0000, 'testTag', 'getAppCloneBundleInfo failed. Cause: %{public}s', err.message); 5345 }); 5346} catch (err) { 5347 let message = (err as BusinessError).message; 5348 hilog.error(0x0000, 'testTag', 'getAppCloneBundleInfo failed. Cause: %{public}s', message); 5349} 5350``` 5351 5352## bundleManager.getAllAppCloneBundleInfo<sup>12+</sup> 5353 5354getAllAppCloneBundleInfo(bundleName: string, bundleFlags: number, userId?: number): Promise\<Array\<BundleInfo>>; 5355 5356根据bundleName、[bundleFlags](js-apis-bundleManager.md#bundleflag)以及用户ID查询主应用和分身应用的BundleInfo列表。使用Promise异步回调。 5357 5358**系统接口:** 此接口为系统接口。 5359 5360**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 5361 5362**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5363 5364**参数:** 5365 5366| 参数名 | 类型 | 必填 | 说明 | 5367| ---------- | ------ | ---- | ---------------------------| 5368| bundleName | number | 是 | 表示要查询的应用Bundle名称。 | 5369| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是 | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。 | 5370| userId | number | 否 | 表示用户ID,默认值:调用方所在用户,取值范围:大于等于0。 | 5371 5372**返回值:** 5373 5374| 类型 | 说明 | 5375| ----------------------------------------------------------- | --------------------------- | 5376| Promise\<Array\<BundleInfo>> | 以Promise方式返回应用包信息列表。 | 5377 5378**错误码:** 5379 5380以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5381 5382| 错误码ID | 错误信息 | 5383| -------- | --------------------------------------| 5384| 201 | Permission denied. | 5385| 202 | Permission denied, non-system app called system api. | 5386| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5387| 17700001 | The specified bundleName is not found. | 5388| 17700004 | The specified userId is invalid. | 5389| 17700026 | The specified bundle and clone apps are all disabled. | 5390 5391**示例:** 5392 5393```ts 5394import { bundleManager } from '@kit.AbilityKit'; 5395import { BusinessError } from '@kit.BasicServicesKit'; 5396import { hilog } from '@kit.PerformanceAnalysisKit'; 5397let bundleName = 'com.example.myapplication'; 5398let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; 5399 5400try { 5401 bundleManager.getAllAppCloneBundleInfo(bundleName, bundleFlags).then((res: Array<bundleManager.BundleInfo>) => { 5402 let index = 0; 5403 for (let item of res) { 5404 hilog.info(0x0000, 'testTag', 'getAllAppCloneBundleInfo res: BundleInfo[%{public}d] = %{public}s', index++, JSON.stringify(item)); 5405 } 5406 }).catch((err: BusinessError) => { 5407 hilog.error(0x0000, 'testTag', 'getAllAppCloneBundleInfo failed. Cause: %{public}s', err.message); 5408 }); 5409} catch (err) { 5410 let message = (err as BusinessError).message; 5411 hilog.error(0x0000, 'testTag', 'getAllAppCloneBundleInfo failed. Cause: %{public}s', message); 5412} 5413``` 5414## bundleManager.verifyAbc<sup>11+</sup> 5415 5416verifyAbc(abcPaths: Array\<string>, deleteOriginalFiles: boolean, callback: AsyncCallback\<void>): void 5417 5418根据给定的abcPaths和deleteOriginalFiles校验.abc文件。使用callback异步回调。 5419 5420**系统接口:** 此接口为系统接口。 5421 5422**需要权限:** ohos.permission.RUN_DYN_CODE 5423 5424**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5425 5426**参数:** 5427 5428| 参数名 | 类型 | 必填 | 说明 | 5429| ----------- | ------ | ---- | ---------------------------- | 5430| abcPaths | Array\<string> | 是 | .abc文件路径。 | 5431| deleteOriginalFiles | boolean | 是 | 是否删除.abc文件,true删除,false不删除。| 5432| callback | AsyncCallback\<void> | 是 | 回调函数,当获取成功时,err为null;否则为错误对象。 | 5433 5434**错误码:** 5435 5436以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5437 5438| 错误码ID | 错误信息 | 5439| -------- | ------------------------------------- | 5440| 201 | Permission denied. | 5441| 202 | Permission denied, non-system app called system api. | 5442| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5443| 17700201 | Failed to verify the abc file. | 5444 5445**示例:** 5446 5447```ts 5448import { bundleManager } from '@kit.AbilityKit'; 5449import { BusinessError } from '@kit.BasicServicesKit'; 5450import { hilog } from '@kit.PerformanceAnalysisKit'; 5451 5452let abcPaths: Array<string> = ['/data/storage/el2/base/a.abc']; 5453 5454try { 5455 bundleManager.verifyAbc(abcPaths, true, (err, data) => { 5456 if (err) { 5457 hilog.error(0x0000, 'testTag', 'verifyAbc failed: %{public}s', err.message); 5458 } else { 5459 hilog.info(0x0000, 'testTag', 'verifyAbc successfully'); 5460 } 5461 }); 5462} catch (err) { 5463 let message = (err as BusinessError).message; 5464 hilog.error(0x0000, 'testTag', 'verifyAbc failed: %{public}s', message); 5465} 5466``` 5467 5468## bundleManager.migrateData<sup>18+</sup> 5469 5470migrateData(sourcePaths: Array<string>, destinationPath: string): Promise<void> 5471 5472拷贝文件,将文件从源路径拷贝到目标路径。使用Promise异步回调。 5473 5474**系统接口:** 此接口为系统接口。 5475 5476**需要权限:** ohos.permission.MIGRATE_DATA 5477 5478**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5479 5480**参数:** 5481 5482| 参数名 | 类型 | 必填 | 说明 | 5483| ----------- | ------ | ---- | -------------------------------------------------------- | 5484| sourcePaths | Array<string> | 是 | 需要迁移的源路径数组,支持传入如/example1/test.txt的单文件路径,或/example2/test的目录路径。 | 5485| destinationPath | string | 是 | 目标路径,仅支持传入一个目录路径,例如:/example2/test。 | 5486 5487**返回值:** 5488 5489| 类型 | 说明 | 5490| ---------- | -------------------- | 5491| Promise\<void> | 无返回结果的Promise对象。 | 5492 5493**错误码:** 5494 5495以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5496 5497| 错误码ID | 错误信息 | 5498| -------- | ------------------------------------- | 5499| 201 | Permission denied. | 5500| 202 | Permission denied, non-system app called system api. | 5501| 17700080 | The source paths are invalid. | 5502| 17700081 | The destination path is invalid. | 5503| 17700082 | User authentication failed. | 5504| 17700083 | Waiting for user authentication timeout. | 5505| 17700084 | There are inaccessible path in the source paths. | 5506| 17700085 | The destination path cannot be accessed. | 5507| 17700086 | System error occurred during copy execution. | 5508 5509**示例:** 5510 5511```ts 5512import { bundleManager } from '@kit.AbilityKit'; 5513import { BusinessError } from '@kit.BasicServicesKit'; 5514 5515try { 5516 // 开发者需将source1、source2、dest内容更新为实际文件路径或目录路径。 5517 let source1: string = "/data/app/el2/100/base/com.example.myapplication/"; 5518 let source2: string = "/data/app/el2/101/base/com.example.myapplication/log.txt"; 5519 let dest: string = "/data/local/tmp" 5520 let sourcePaths: Array<string> = [source1, source2]; 5521 5522 bundleManager.migrateData(sourcePaths, dest) 5523 .then(() => { 5524 console.info(`migrateData succeed`); 5525 }) 5526 .catch((err: BusinessError) => { 5527 console.error(`migrateData err : `, JSON.stringify(err)); 5528 }) 5529} catch(err) { 5530 console.error(`migrateData call err : `, JSON.stringify(err)); 5531} 5532``` 5533 5534## bundleManager.verifyAbc<sup>11+</sup> 5535 5536verifyAbc(abcPaths: Array\<string>, deleteOriginalFiles: boolean): Promise\<void> 5537 5538根据给定的abcPaths和deleteOriginalFiles校验.abc文件。使用Promise异步回调。 5539 5540**系统接口:** 此接口为系统接口。 5541 5542**需要权限:** ohos.permission.RUN_DYN_CODE 5543 5544**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5545 5546**参数:** 5547 5548| 参数名 | 类型 | 必填 | 说明 | 5549| ----------- | ------ | ---- | ---------------------------- | 5550| abcPaths | Array\<string> | 是 | .abc文件路径。 | 5551| deleteOriginalFiles | boolean | 是 | 是否删除.abc文件,true删除,false不删除。 | 5552 5553**返回值:** 5554 5555| 类型 | 说明 | 5556| ----------------------------------------------------------- | --------------------------- | 5557| Promise\<void> | 无返回结果的Promise对象。 | 5558 5559**错误码:** 5560 5561以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5562 5563| 错误码ID | 错误信息 | 5564| -------- | --------------------------------------| 5565| 201 | Permission denied. | 5566| 202 | Permission denied, non-system app called system api. | 5567| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5568| 17700201 | Failed to verify the abc file. | 5569 5570**示例:** 5571 5572```ts 5573import { bundleManager } from '@kit.AbilityKit'; 5574import { BusinessError } from '@kit.BasicServicesKit'; 5575import { hilog } from '@kit.PerformanceAnalysisKit'; 5576 5577let abcPaths: Array<string> = ['/data/storage/el2/base/a.abc']; 5578 5579try { 5580 bundleManager.verifyAbc(abcPaths, true).then((data) => { 5581 hilog.info(0x0000, 'testTag', 'verifyAbc successfully'); 5582 }).catch((err: BusinessError) => { 5583 hilog.error(0x0000, 'testTag', 'verifyAbc failed. Cause: %{public}s', err.message); 5584 }); 5585} catch (err) { 5586 let message = (err as BusinessError).message; 5587 hilog.error(0x0000, 'testTag', 'verifyAbc failed. Cause: %{public}s', message); 5588} 5589``` 5590 5591## bundleManager.deleteAbc<sup>11+</sup> 5592 5593deleteAbc(abcPath: string): Promise\<void> 5594 5595根据给定的abcPath删除.abc文件。使用Promise异步回调。 5596 5597**系统接口:** 此接口为系统接口。 5598 5599**需要权限:** ohos.permission.RUN_DYN_CODE 5600 5601**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 5602 5603**参数:** 5604 5605| 参数名 | 类型 | 必填 | 说明 | 5606| ----------- | ------ | ---- | ---------------------------- | 5607| abcPath | string | 是 | .abc文件路径。 | 5608 5609**返回值:** 5610 5611| 类型 | 说明 | 5612| ----------------------------------------------------------- | --------------------------- | 5613| Promise\<void> | 无返回结果的Promise对象。 | 5614 5615**错误码:** 5616 5617以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 5618 5619| 错误码ID | 错误信息 | 5620| -------- | --------------------------------------| 5621| 201 | Permission denied. | 5622| 202 | Permission denied, non-system app called system api. | 5623| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 5624| 17700202 | Failed to delete the abc file. | 5625 5626**示例:** 5627 5628```ts 5629import { bundleManager } from '@kit.AbilityKit'; 5630import { BusinessError } from '@kit.BasicServicesKit'; 5631import { hilog } from '@kit.PerformanceAnalysisKit'; 5632 5633let abcPath: string = '/data/storage/el2/base/a.abc'; 5634 5635try { 5636 bundleManager.deleteAbc(abcPath).then((data) => { 5637 hilog.info(0x0000, 'testTag', 'deleteAbc successfully'); 5638 }).catch((err: BusinessError) => { 5639 hilog.error(0x0000, 'testTag', 'deleteAbc failed. Cause: %{public}s', err.message); 5640 }); 5641} catch (err) { 5642 let message = (err as BusinessError).message; 5643 hilog.error(0x0000, 'testTag', 'deleteAbc failed. Cause: %{public}s', message); 5644} 5645```