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