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