1# @ohos.bundle.bundleManager (bundleManager) 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## Modules to Import 10 11```ts 12import bundleManager from '@ohos.bundle.bundleManager'; 13``` 14 15## Required Permissions 16 17| Permission | APL | Description | 18| ------------------------------------------ | ------------ | ------------------| 19| ohos.permission.GET_BUNDLE_INFO | normal | Permission to obtain basic information about a bundle. | 20| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to obtain basic information and other sensitive information about a bundle.| 21| ohos.permission.REMOVE_CACHE_FILES | system_basic | Permission to clear cache files of a bundle. | 22|ohos.permission.CHANGE_ABILITY_ENABLED_STATE| system_basic | Permission to enable or disable an application or ability. | 23| ohos.permission.GET_INSTALLED_BUNDLE_LIST | system_basic | Permission to read installed application list.| 24 25For details, see [Permission APL](../../security/AccessToken/app-permission-mgmt-overview.md#permission-apl). 26 27## Enums 28 29### BundleFlag 30 31Enumerates the bundle flags, which indicate the type of bundle information to obtain. 32 33 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 34 35| Name | Value | Description | 36| ----------------------------------------- | ---------- | ------------------------------------------------------------ | 37| GET_BUNDLE_INFO_DEFAULT | 0x00000000 | Used to obtain the default bundle information. The obtained information does not contain information about the signature, application, HAP module, ability, ExtensionAbility, or permission.| 38| GET_BUNDLE_INFO_WITH_APPLICATION | 0x00000001 | Used to obtain the bundle information with application information. The obtained information does not contain information about the signature, HAP module, ability, ExtensionAbility, or permission.| 39| GET_BUNDLE_INFO_WITH_HAP_MODULE | 0x00000002 | Used to obtain the bundle information with HAP module information. The obtained information does not contain information about the signature, application, ability, ExtensionAbility, or permission.| 40| GET_BUNDLE_INFO_WITH_ABILITY | 0x00000004 | Used to obtain the bundle information with ability information. The obtained information does not contain information about the signature, application, ExtensionAbility, or permission. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**.| 41| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY | 0x00000008 | Used to obtain the bundle information with ExtensionAbility information. The obtained information does not contain information about the signature, application, ability, or permission. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**.| 42| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION | 0x00000010 | Used to obtain the bundle information with permission information. The obtained information does not contain information about the signature, application, HAP module, ability, or ExtensionAbility.| 43| GET_BUNDLE_INFO_WITH_METADATA | 0x00000020 | Used to obtain the metadata contained in the application, HAP module, ability, or ExtensionAbility information. It must be used together with **GET_BUNDLE_INFO_WITH_APPLICATION**, **GET_BUNDLE_INFO_WITH_HAP_MODULE**, **GET_BUNDLE_INFO_WITH_ABILITY**, and **GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY**.| 44| GET_BUNDLE_INFO_WITH_DISABLE | 0x00000040 | Used to obtain the information about disabled bundles and abilities of a bundle. The obtained information does not contain information about the signature, application, HAP module, ability, ExtensionAbility, or permission.| 45| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO | 0x00000080 | Used to obtain the bundle information with signature information. The obtained information does not contain information about the application, HAP module, ability, ExtensionAbility, or permission.| 46| GET_BUNDLE_INFO_WITH_MENU<sup>11+</sup> | 0x00000100 | Used to obtain the bundle information with the file context menu configuration. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**.| 47 48### ApplicationFlag 49 50Enumerates the application flags, which indicate the type of application information to obtain. 51 52 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 53 54 **System API**: This is a system API. 55 56| Name | Value | Description | 57| ------------------------------------ | ---------- | ------------------------------------------------------------ | 58| GET_APPLICATION_INFO_DEFAULT | 0x00000000 | Used to obtain the default application information. The obtained information does not contain the permission information or metadata.| 59| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the application information with permission information. | 60| GET_APPLICATION_INFO_WITH_METADATA | 0x00000002 | Used to obtain the application information with metadata. | 61| GET_APPLICATION_INFO_WITH_DISABLE | 0x00000004 | Used to obtain the application information of disabled bundles. | 62 63### AbilityFlag 64 65Enumerates the ability flags, which indicate the type of ability 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_ABILITY_INFO_DEFAULT | 0x00000000 | Used to obtain the default ability information. The obtained information does not contain the permission, metadata, or disabled ability information.| 74| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the ability information with permission information. | 75| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | Used to obtain the ability information with application information. | 76| GET_ABILITY_INFO_WITH_METADATA | 0x00000004 | Used to obtain the ability information with metadata. | 77| GET_ABILITY_INFO_WITH_DISABLE | 0x00000008 | Used to obtain the ability information of disabled abilities. | 78| GET_ABILITY_INFO_ONLY_SYSTEM_APP | 0x00000010 | Used to obtain the ability information of system applications. | 79 80### ExtensionAbilityFlag 81 82Enumerates the ExtensionAbility flags, which indicate the type of ExtensionAbility information to obtain. 83 84 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 85 86 **System API**: This is a system API. 87 88| Name | Value | Description | 89| ------------------------------------------- | ---------- | ------------------------------------------------------------ | 90| 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.| 91| GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the ExtensionAbility information with permission information. | 92| GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | Used to obtain the ExtensionAbility information with application information. | 93| GET_EXTENSION_ABILITY_INFO_WITH_METADATA | 0x00000004 | Used to obtain the ExtensionAbility information with metadata. | 94 95### ExtensionAbilityType 96 97Enumerates the types of ExtensionAbilities. 98 99 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 100 101| Name| Value| Description| 102|:----------------:|:---:|-----| 103| FORM | 0 | [FormExtensionAbility](js-apis-app-form-formExtensionAbility.md): provides APIs for widget development.| 104| WORK_SCHEDULER | 1 | provides APIs for widget development.: enables applications to execute non-real-time tasks when the system is idle.| 105| INPUT_METHOD | 2 | [InputMethodExtensionAbility](js-apis-inputmethod-extension-ability.md): provides APIs for developing input method applications.| 106| SERVICE | 3 | [ServiceExtensionAbility](js-apis-app-ability-serviceExtensionAbility.md): enables applications to run in the background and provide services.| 107| ACCESSIBILITY | 4 | [AccessibilityExtensionAbility](js-apis-application-accessibilityExtensionAbility.md): provides accessibility for access to and operations on the UI.| 108| DATA_SHARE | 5 | [DataShareExtensionAbility](js-apis-application-dataShareExtensionAbility.md): enables applications to read and write data.| 109| FILE_SHARE | 6 | FileShareExtensionAbility: enables file sharing between applications. This ability is reserved.| 110| STATIC_SUBSCRIBER| 7 | [StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md): provides APIs for processing static events, such as the startup event.| 111| WALLPAPER | 8 | WallpaperExtensionAbility: provides APIs to implement the home screen wallpaper. This ability is reserved.| 112| BACKUP | 9 | [BackupExtensionAbility](js-apis-application-backupExtensionAbility.md): provides APIs to implement application data backup and restore.| 113| WINDOW | 10 | [WindowExtensionAbility](js-apis-application-windowExtensionAbility.md): allows system applications to display UIs of other applications.| 114| ENTERPRISE_ADMIN | 11 | [EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md): provides APIs for processing enterprise management events, such as application installation events on devices and events indicating too many incorrect screen-lock password attempts.| 115| THUMBNAIL | 13 | ThumbnailExtensionAbility: provides thumbnails for files. This ability is reserved.| 116| PREVIEW | 14 | PreviewExtensionAbility: provides APIs for file preview so that other applications can be embedded and displayed in the current application. This ability is reserved.| 117| PRINT<sup>10+</sup> | 15 | PrintExtensionAbility: provides APIs for printing images. Printing documents is not supported yet.| 118| SHARE<sup>10+</sup> | 16 | [ShareExtensionAbility](js-apis-app-ability-shareExtensionAbility.md): provides sharing service templates based on UIExtensionAbilities.| 119| PUSH<sup>10+</sup> | 17 | PushExtensionAbility: provides APIs for pushing scenario-specific messages. This ability is reserved.| 120| DRIVER<sup>10+</sup> | 18 | [DriverExtensionAbility](js-apis-app-ability-driverExtensionAbility.md): provides APIs for the peripheral driver. This type of ability is not supported yet.| 121| ACTION<sup>10+</sup> | 19 | [ActionExtensionAbility](js-apis-app-ability-actionExtensionAbility.md): provides custom action service templates based on UIExtensionAbilities.| 122| ADS_SERVICE<sup>11+</sup> | 20 | AdsServiceExtensionAbility: provides background customized ad services for external systems. This type of ability is not supported yet.| 123| UNSPECIFIED | 255 | No type is specified. It is used together with **queryExtensionAbilityInfo** to query all types of ExtensionAbilities.| 124 125 126### PermissionGrantState 127 128Enumerates the permission grant states. 129 130 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 131 132| Name| Value| Description| 133|:----------------:|:---:|:---:| 134| PERMISSION_DENIED| -1 | Permission denied.| 135| PERMISSION_GRANTED | 0 | Permission granted. | 136 137### SupportWindowMode 138 139Enumerates the window modes supported by the ability. 140 141 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 142 143| Name| Value| Description| 144|:----------------:|:---:|:---:| 145| FULL_SCREEN | 0 | A window in full-screen mode is supported.| 146| SPLIT | 1 | A window in split-screen mode is supported.| 147| FLOATING | 2 | A floating window is supported. | 148 149### LaunchType 150 151Enumerates the launch types of the ability. 152 153 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 154 155| Name| Value| Description| 156|:----------------:|:---:|:---:| 157| SINGLETON | 0 | The ability can have only one instance.| 158| MULTITON | 1 | The ability can have multiple instances.| 159| SPECIFIED | 2 | The ability can have one or multiple instances, depending on the internal service of the ability.| 160 161### AbilityType 162 163Enumerates the types of abilities. 164 165 **Model restriction**: This API can be used only in the FA model. 166 167 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 168 169| Name | Value | Description | 170| :-----: | ---- | :--------------------------------------------------------: | 171| PAGE | 1 | FA developed using the Page template to provide the capability of interacting with users. | 172| SERVICE | 2 | PA developed using the Service template to provide the capability of running tasks in the background. | 173| DATA | 3 | PA developed using the Data template to provide unified data access for external systems.| 174 175### DisplayOrientation 176 177Enumerates the display orientations of the ability. This attribute applies only to the ability using the Page template. 178 179 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 180 181| Name |Value|Description| 182|:----------------------------------|---|---| 183| UNSPECIFIED |0 |Unspecified. The orientation is determined by the system.| 184| LANDSCAPE |1 |Landscape.| 185| PORTRAIT |2 |Portrait.| 186| FOLLOW_RECENT |3 |The last display orientation is used.| 187| LANDSCAPE_INVERTED |4 |Reverse landscape.| 188| PORTRAIT_INVERTED |5 |Reverse portrait.| 189| AUTO_ROTATION |6 |Auto rotation.| 190| AUTO_ROTATION_LANDSCAPE |7 |Auto rotation in the horizontal direction.| 191| AUTO_ROTATION_PORTRAIT |8 |Auto rotation in the vertical direction.| 192| AUTO_ROTATION_RESTRICTED |9 |Switched-determined auto rotation.| 193| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|Switched-determined auto rotation in the horizontal direction.| 194| AUTO_ROTATION_PORTRAIT_RESTRICTED |11|Switched-determined auto rotation in the vertical direction.| 195| LOCKED |12|Locked.| 196 197### CompatiblePolicy<sup>10+</sup> 198 199Defines the version compatibility type of the shared library. 200 201 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 202 203| Name | Value | Description | 204| ---------------------- | ---- | -------------------------------- | 205| BACKWARD_COMPATIBILITY | 1 | The shared library is backward compatible.| 206 207### ModuleType 208 209Enumerates the module types. 210 211 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 212 213| Name | Value | Description | 214| ------- | ---- | -------------------- | 215| ENTRY | 1 | Main module of the application. | 216| FEATURE | 2 | Dynamic feature module of the application.| 217| SHARED | 3 | Dynamic shared library module of the application. | 218 219### BundleType 220 221Enumerates the bundle types. 222 223 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 224 225| Name | Value | Description | 226| -------------- | ---- | --------------- | 227| APP | 0 | The bundle is an application. | 228| ATOMIC_SERVICE | 1 | The bundle is an atomic service.| 229 230### ProfileType<sup>11+</sup> 231 232Enumerates the types of profiles (also called application files). 233 234 **System capability**: SystemCapability.BundleManager.BundleFramework.Core 235 236 **System API**: This is a system API. 237 238| Name | Value | Description | 239| -------------- | ---- | --------------- | 240| INTENT_PROFILE | 1 | Profile of the InsightIntent framework. | 241 242## APIs 243 244### bundleManager.getBundleInfoForSelf 245 246getBundleInfoForSelf(bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> 247 248Obtains the bundle information of this bundle based on the given bundle flags. This API uses a promise to return the result. 249 250**System capability**: SystemCapability.BundleManager.BundleFramework.Core 251 252**Parameters** 253 254| Name | Type | Mandatory| Description | 255| ----------- | ------ | ---- | --------------------- | 256| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 257 258**Return value** 259 260| Type | Description | 261| ----------------------------------------------------------- | ------------------------------------- | 262| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information.| 263 264**Example** 265 266```ts 267// Obtain application info with metadataArray. 268import bundleManager from '@ohos.bundle.bundleManager'; 269import { BusinessError } from '@ohos.base'; 270import hilog from '@ohos.hilog'; 271let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; 272try { 273 bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { 274 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); 275 }).catch((err: BusinessError) => { 276 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message); 277 }); 278} catch (err) { 279 let message = (err as BusinessError).message; 280 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message); 281} 282``` 283 284### bundleManager.getBundleInfoForSelf 285 286getBundleInfoForSelf(bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void 287 288Obtains the bundle information of this bundle based on the given bundle flags. This API uses an asynchronous callback to return the result. 289 290**System capability**: SystemCapability.BundleManager.BundleFramework.Core 291 292**Parameters** 293 294| Name | Type | Mandatory| Description | 295| ----------- | ------ | ---- | --------------------- | 296| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 297| 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.| 298 299**Example** 300 301```ts 302// Obtain ability info with permissions. 303import bundleManager from '@ohos.bundle.bundleManager'; 304import { BusinessError } from '@ohos.base'; 305import hilog from '@ohos.hilog'; 306let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 307 308try { 309 bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => { 310 if (err) { 311 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message); 312 } else { 313 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data)); 314 } 315 }); 316} catch (err) { 317 let message = (err as BusinessError).message; 318 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message); 319} 320``` 321 322### bundleManager.getBundleInfo 323 324getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void 325 326Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses an asynchronous callback to return the result. 327 328No permission is required for obtaining the caller's own information. 329 330**System API**: This is a system API. 331 332**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 333 334**System capability**: SystemCapability.BundleManager.BundleFramework.Core 335 336**Parameters** 337 338| Name | Type | Mandatory| Description | 339| ----------- | ------ | ---- | ---------------------------- | 340| bundleName | string | Yes | Bundle name.| 341| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 342| userId | number | Yes | User ID. | 343| 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.| 344 345**Error codes** 346 347For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 348 349| ID| Error Message | 350| -------- | ------------------------------------- | 351| 17700001 | The specified bundleName is not found. | 352| 17700004 | The specified user ID is not found. | 353| 17700026 | The specified bundle is disabled. | 354 355**Example** 356 357```ts 358// Obtain the bundle information with the ability information. 359import bundleManager from '@ohos.bundle.bundleManager'; 360import { BusinessError } from '@ohos.base'; 361import hilog from '@ohos.hilog'; 362let bundleName = 'com.example.myapplication'; 363let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY; 364let userId = 100; 365 366try { 367 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 368 if (err) { 369 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 370 } else { 371 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 372 } 373 }); 374} catch (err) { 375 let message = (err as BusinessError).message; 376 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 377} 378``` 379 380```ts 381// Obtain the bundle information with the metadata in the application information. 382import bundleManager from '@ohos.bundle.bundleManager'; 383import { BusinessError } from '@ohos.base'; 384import hilog from '@ohos.hilog'; 385let bundleName = 'com.example.myapplication'; 386let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; 387let userId = 100; 388 389try { 390 bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => { 391 if (err) { 392 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 393 } else { 394 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 395 } 396 }); 397} catch (err) { 398 let message = (err as BusinessError).message; 399 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 400} 401``` 402 403### bundleManager.getBundleInfo 404 405getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void 406 407Obtains the bundle information based on the given bundle name and bundle flags. This API uses an asynchronous callback to return the result. 408 409No permission is required for obtaining the caller's own information. 410 411**System API**: This is a system API. 412 413**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 414 415**System capability**: SystemCapability.BundleManager.BundleFramework.Core 416 417**Parameters** 418 419| Name | Type | Mandatory| Description | 420| ----------- | ------ | ---- | ---------------------------- | 421| bundleName | string | Yes | Bundle name.| 422| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 423| 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.| 424 425**Error codes** 426 427For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 428 429| ID| Error Message | 430| -------- | ------------------------------------- | 431| 17700001 | The specified bundleName is not found. | 432| 17700026 | The specified bundle is disabled. | 433 434**Example** 435 436```ts 437// Obtain the bundle information with the ExtensionAbility information. 438import bundleManager from '@ohos.bundle.bundleManager'; 439import { BusinessError } from '@ohos.base'; 440import hilog from '@ohos.hilog'; 441let bundleName = 'com.example.myapplication'; 442let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY; 443 444try { 445 bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => { 446 if (err) { 447 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message); 448 } else { 449 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data)); 450 } 451 }); 452} catch (err) { 453 let message = (err as BusinessError).message; 454 hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message); 455} 456``` 457 458### bundleManager.getBundleInfo 459 460getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: number): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> 461 462Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses a promise to return the result. 463 464No permission is required for obtaining the caller's own information. 465 466**System API**: This is a system API. 467 468**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 469 470**System capability**: SystemCapability.BundleManager.BundleFramework.Core 471 472**Parameters** 473 474| Name | Type | Mandatory| Description | 475| ----------- | ------ | ---- | ---------------------------- | 476| bundleName | string | Yes | Bundle name.| 477| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 478| 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. | 479 480**Return value** 481 482| Type | Description | 483| ----------------------------------------------------------- | --------------------------- | 484| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information obtained.| 485 486**Error codes** 487 488For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 489 490| ID| Error Message | 491| -------- | --------------------------------------| 492| 17700001 | The specified bundleName is not found. | 493| 17700004 | The specified user ID is not found. | 494| 17700026 | The specified bundle is disabled. | 495 496**Example** 497 498```ts 499// Obtain the bundle information with the application and signature information. 500import bundleManager from '@ohos.bundle.bundleManager'; 501import { BusinessError } from '@ohos.base'; 502import hilog from '@ohos.hilog'; 503let bundleName = 'com.example.myapplication'; 504let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; 505let userId = 100; 506 507try { 508 bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => { 509 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 510 }).catch((err: BusinessError) => { 511 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 512 }); 513} catch (err) { 514 let message = (err as BusinessError).message; 515 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message); 516} 517``` 518 519```ts 520import bundleManager from '@ohos.bundle.bundleManager'; 521import { BusinessError } from '@ohos.base'; 522import hilog from '@ohos.hilog'; 523let bundleName = 'com.example.myapplication'; 524let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 525 526try { 527 bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => { 528 hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 529 }).catch((err: BusinessError) => { 530 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message); 531 }); 532} catch (err) { 533 let message = (err as BusinessError).message; 534 hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message); 535} 536 537``` 538 539### bundleManager.getApplicationInfo 540 541getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void 542 543Obtains the application information based on the given bundle name, application flags, and user ID. This API uses an asynchronous callback to return the result. 544 545No permission is required for obtaining the caller's own information. 546 547**System API**: This is a system API. 548 549**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 550 551**System capability**: SystemCapability.BundleManager.BundleFramework.Core 552 553**Parameters** 554 555| Name | Type | Mandatory| Description | 556| ---------- | ------ | ---- | ---------------------------- | 557| bundleName | string | Yes | Bundle name.| 558| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 559| userId | number | Yes | User ID. | 560| 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.| 561 562**Error codes** 563 564For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 565 566| ID| Error Message | 567| -------- | --------------------------------------| 568| 17700001 | The specified bundleName is not found. | 569| 17700004 | The specified user ID is not found. | 570| 17700026 | The specified bundle is disabled. | 571 572**Example** 573 574```ts 575import bundleManager from '@ohos.bundle.bundleManager'; 576import { BusinessError } from '@ohos.base'; 577import hilog from '@ohos.hilog'; 578let bundleName = 'com.example.myapplication'; 579let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 580let userId = 100; 581 582try { 583 bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => { 584 if (err) { 585 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 586 } else { 587 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 588 } 589 }); 590} catch (err) { 591 let message = (err as BusinessError).message; 592 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message); 593} 594``` 595 596### bundleManager.getApplicationInfo 597 598getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void 599 600Obtains the application information based on the given bundle name and application flags. This API uses an asynchronous callback to return the result. 601 602No permission is required for obtaining the caller's own information. 603 604**System API**: This is a system API. 605 606**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 607 608**System capability**: SystemCapability.BundleManager.BundleFramework.Core 609 610**Parameters** 611 612| Name | Type | Mandatory| Description | 613| ---------- | ------ | ---- | ---------------------------- | 614| bundleName | string | Yes | Bundle name.| 615| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 616| 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.| 617 618**Error codes** 619 620For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 621 622| ID| Error Message | 623| -------- | --------------------------------------| 624| 17700001 | The specified bundleName is not found. | 625| 17700026 | The specified bundle is disabled. | 626 627**Example** 628 629```ts 630import bundleManager from '@ohos.bundle.bundleManager'; 631import { BusinessError } from '@ohos.base'; 632import hilog from '@ohos.hilog'; 633let bundleName = 'com.example.myapplication'; 634let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 635 636try { 637 bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => { 638 if (err) { 639 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message); 640 } else { 641 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data)); 642 } 643 }); 644} catch (err) { 645 let message = (err as BusinessError).message; 646 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', message); 647} 648``` 649 650### bundleManager.getApplicationInfo 651 652getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId?: number): Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> 653 654Obtains the application information based on the given bundle name, application flags, and user ID. This API uses a promise to return the result. 655 656No permission is required for obtaining the caller's own information. 657 658**System API**: This is a system API. 659 660**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 661 662**System capability**: SystemCapability.BundleManager.BundleFramework.Core 663 664**Parameters** 665 666| Name | Type | Mandatory| Description | 667| ---------- | ------ | ---- | ---------------------------- | 668| bundleName | string | Yes | Bundle name.| 669| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 670| 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.| 671 672**Return value** 673 674| Type | Description | 675| ------------------------------------------------------------ | -------------------------------- | 676| Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Promise used to return the application information obtained.| 677 678**Error codes** 679 680For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 681 682| ID| Error Message | 683| -------- | ------------------------------------- | 684| 17700001 | The specified bundleName is not found. | 685| 17700004 | The specified user ID is not found. | 686| 17700026 | The specified bundle is disabled. | 687 688**Example** 689 690```ts 691import bundleManager from '@ohos.bundle.bundleManager'; 692import { BusinessError } from '@ohos.base'; 693import hilog from '@ohos.hilog'; 694let bundleName = 'com.example.myapplication'; 695let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION; 696let userId = 100; 697 698try { 699 bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => { 700 hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 701 }).catch((err: BusinessError) => { 702 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message); 703 }); 704} catch (err) { 705 let message = (err as BusinessError).message; 706 hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', message); 707} 708``` 709 710### bundleManager.getAllBundleInfo 711 712getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void 713 714Obtains the information about all bundles based on the given bundle flags and user ID. This API uses an asynchronous callback to return the result. 715 716**System API**: This is a system API. 717 718**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST 719 720**System capability**: SystemCapability.BundleManager.BundleFramework.Core 721 722**Parameters** 723 724| Name | Type | Mandatory| Description | 725| ----------- | ------ | ---- | -------------------------------------------------- | 726| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 727| userId | number | Yes | User ID. | 728| 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.| 729 730**Error codes** 731 732For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 733 734| ID| Error Message | 735| -------- | --------------------------------- | 736| 17700004 | The specified user ID is not found. | 737 738**Example** 739 740```ts 741import bundleManager from '@ohos.bundle.bundleManager'; 742import { BusinessError } from '@ohos.base'; 743import hilog from '@ohos.hilog'; 744let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 745let userId = 100; 746 747try { 748 bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => { 749 if (err) { 750 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 751 } else { 752 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 753 } 754 }); 755} catch (err) { 756 let message = (err as BusinessError).message; 757 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message); 758} 759``` 760 761### bundleManager.getAllBundleInfo 762 763getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void 764 765Obtains the information about all bundles based on the given bundle flags. This API uses an asynchronous callback to return the result. 766 767**System API**: This is a system API. 768 769**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST 770 771**System capability**: SystemCapability.BundleManager.BundleFramework.Core 772 773**Parameters** 774 775| Name | Type | Mandatory| Description | 776| ----------- | ------ | ---- | -------------------------------------------------- | 777| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 778| 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.| 779 780**Example** 781 782```ts 783import bundleManager from '@ohos.bundle.bundleManager'; 784import { BusinessError } from '@ohos.base'; 785import hilog from '@ohos.hilog'; 786let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 787 788try { 789 bundleManager.getAllBundleInfo(bundleFlags, (err, data) => { 790 if (err) { 791 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message); 792 } else { 793 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data)); 794 } 795 }); 796} catch (err) { 797 let message = (err as BusinessError).message; 798 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', message); 799} 800``` 801 802### bundleManager.getAllBundleInfo 803 804getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> 805 806Obtains the information about all bundles based on the given bundle flags and user ID. This API uses a promise to return the result. 807 808**System API**: This is a system API. 809 810**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST 811 812**System capability**: SystemCapability.BundleManager.BundleFramework.Core 813 814**Parameters** 815 816| Name | Type | Mandatory| Description | 817| ----------- | ------ | ---- | -------------------------------------------------- | 818| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 819| 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. | 820 821**Return value** 822 823| Type | Description | 824| ------------------------------------------------------------ | ----------------------------------- | 825| Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Promise used to return the array of bundle information obtained.| 826 827**Error codes** 828 829For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 830 831| ID| Error Message | 832| -------- | ---------------------------------- | 833| 17700004 | The specified user ID is not found. | 834 835**Example** 836 837```ts 838import bundleManager from '@ohos.bundle.bundleManager'; 839import { BusinessError } from '@ohos.base'; 840import hilog from '@ohos.hilog'; 841let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 842 843try { 844 bundleManager.getAllBundleInfo(bundleFlags).then((data) => { 845 hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 846 }).catch((err: BusinessError) => { 847 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message); 848 }); 849} catch (err) { 850 let message = (err as BusinessError).message; 851 hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', message); 852} 853``` 854 855### bundleManager.getAllApplicationInfo 856 857getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void 858 859Obtains the information about all applications based on the given application flags and user ID. This API uses an asynchronous callback to return the result. 860 861**System API**: This is a system API. 862 863**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST 864 865**System capability**: SystemCapability.BundleManager.BundleFramework.Core 866 867**Parameters** 868 869| Name | Type | Mandatory| Description | 870| -------- | ------ | ---- | ----------------------------------------------------------- | 871| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 872| userId | number | Yes | User ID. | 873| 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.| 874 875**Error codes** 876 877For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 878 879| ID| Error Message | 880| -------- | ---------------------------------- | 881| 17700004 | The specified user ID is not found. | 882 883**Example** 884 885```ts 886import bundleManager from '@ohos.bundle.bundleManager'; 887import { BusinessError } from '@ohos.base'; 888import hilog from '@ohos.hilog'; 889let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 890let userId = 100; 891 892try { 893 bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => { 894 if (err) { 895 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 896 } else { 897 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 898 } 899 }); 900} catch (err) { 901 let message = (err as BusinessError).message; 902 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message); 903} 904``` 905 906### bundleManager.getAllApplicationInfo 907 908getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void 909 910Obtains the information about all applications based on the given application flags. This API uses an asynchronous callback to return the result. 911 912**System API**: This is a system API. 913 914**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST 915 916**System capability**: SystemCapability.BundleManager.BundleFramework.Core 917 918**Parameters** 919 920| Name | Type | Mandatory| Description | 921| -------- | ------ | ---- | ----------------------------------------------------------- | 922| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 923| 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.| 924 925**Example** 926 927```ts 928import bundleManager from '@ohos.bundle.bundleManager'; 929import { BusinessError } from '@ohos.base'; 930import hilog from '@ohos.hilog'; 931let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 932 933try { 934 bundleManager.getAllApplicationInfo(appFlags, (err, data) => { 935 if (err) { 936 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message); 937 } else { 938 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data)); 939 } 940 }); 941} catch (err) { 942 let message = (err as BusinessError).message; 943 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', message); 944} 945``` 946 947### bundleManager.getAllApplicationInfo 948 949getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> 950 951Obtains the information about all applications based on the given application flags and user ID. This API uses a promise to return the result. 952 953**System API**: This is a system API. 954 955**Required permissions**: ohos.permission.GET_INSTALLED_BUNDLE_LIST 956 957**System capability**: SystemCapability.BundleManager.BundleFramework.Core 958 959**Parameters** 960 961| Name | Type | Mandatory| Description | 962| -------- | ------ | ---- | ---------------------------------------------------------- | 963| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 964| 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. | 965 966**Return value** 967 968| Type | Description | 969| ------------------------------------------------------------ | ---------------------------------------- | 970| Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Promise used to return the array of application information obtained.| 971 972**Error codes** 973 974For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 975 976| ID| Error Message | 977| -------- | ---------------------------------- | 978| 17700004 | The specified user ID is not found. | 979 980**Example** 981 982```ts 983import bundleManager from '@ohos.bundle.bundleManager'; 984import { BusinessError } from '@ohos.base'; 985import hilog from '@ohos.hilog'; 986let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 987 988try { 989 bundleManager.getAllApplicationInfo(appFlags).then((data) => { 990 hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data)); 991 }).catch((err: BusinessError) => { 992 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message); 993 }); 994} catch (err) { 995 let message = (err as BusinessError).message; 996 hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', message); 997} 998 999``` 1000 1001### bundleManager.queryAbilityInfo 1002 1003queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: number, callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void 1004 1005Obtains 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. 1006 1007**System API**: This is a system API. 1008 1009**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1010 1011**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1012 1013**Parameters** 1014 1015| Name | Type | Mandatory| Description | 1016| ------------ | ------ | ---- | ------------------------------------------------------- | 1017| want | Want | Yes | Want containing the bundle name to query. | 1018| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain. | 1019| userId | number | Yes | User ID. | 1020| 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.| 1021 1022**Error codes** 1023 1024For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1025 1026| ID| Error Message | 1027| -------- | -------------------------------------- | 1028| 17700001 | The specified bundleName is not found. | 1029| 17700003 | The specified ability is not found. | 1030| 17700004 | The specified userId is invalid. | 1031| 17700026 | The specified bundle is disabled. | 1032| 17700029 | The specified ability is disabled. | 1033 1034**Example** 1035 1036```ts 1037import bundleManager from '@ohos.bundle.bundleManager'; 1038import { BusinessError } from '@ohos.base'; 1039import hilog from '@ohos.hilog'; 1040import Want from '@ohos.app.ability.Want'; 1041let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1042let userId = 100; 1043let want: Want = { 1044 bundleName : "com.example.myapplication", 1045 abilityName : "EntryAbility" 1046}; 1047 1048try { 1049 bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => { 1050 if (err) { 1051 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1052 } else { 1053 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1054 } 1055 }); 1056} catch (err) { 1057 let message = (err as BusinessError).message; 1058 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message); 1059} 1060``` 1061 1062### bundleManager.queryAbilityInfo 1063 1064queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void 1065 1066Obtains an array of ability information based on the given want and ability flags. This API uses an asynchronous callback to return the result. 1067 1068**System API**: This is a system API. 1069 1070**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1071 1072**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1073 1074**Parameters** 1075 1076| Name | Type | Mandatory| Description | 1077| ------------ | ------ | ---- | -------------------------------------------------------| 1078| want | Want | Yes | Want containing the bundle name to query. | 1079| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain. | 1080| 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.| 1081 1082**Error codes** 1083 1084For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1085 1086| ID| Error Message | 1087| -------- | -------------------------------------- | 1088| 17700001 | The specified bundleName is not found. | 1089| 17700003 | The specified ability is not found. | 1090| 17700026 | The specified bundle is disabled. | 1091| 17700029 | The specified ability is disabled. | 1092 1093**Example** 1094 1095```ts 1096import bundleManager from '@ohos.bundle.bundleManager'; 1097import { BusinessError } from '@ohos.base'; 1098import hilog from '@ohos.hilog'; 1099import Want from '@ohos.app.ability.Want'; 1100let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1101let want: Want = { 1102 bundleName : "com.example.myapplication", 1103 abilityName : "EntryAbility" 1104}; 1105 1106try { 1107 bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => { 1108 if (err) { 1109 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message); 1110 } else { 1111 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1112 } 1113 }); 1114} catch (err) { 1115 let message = (err as BusinessError).message; 1116 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', message); 1117} 1118``` 1119 1120### bundleManager.queryAbilityInfo 1121 1122queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> 1123 1124Obtains the ability information based on the given want, ability flags, and user ID. This API uses a promise to return the result. 1125 1126**System API**: This is a system API. 1127 1128**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1129 1130**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1131 1132**Parameters** 1133 1134| Name | Type | Mandatory| Description | 1135| ------------ | ------ | ---- | ------------------------------------------------------- | 1136| want | Want | Yes | Want containing the bundle name to query. | 1137| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain.| 1138| 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. | 1139 1140**Return value** 1141 1142| Type | Description | 1143| ------------------------------------------------------------ | ------------------------------------ | 1144| Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Promise used to return the array of ability information obtained.| 1145 1146**Error codes** 1147 1148For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1149 1150| ID| Error Message | 1151| -------- | ------------------------------------- | 1152| 17700001 | The specified bundleName is not found. | 1153| 17700003 | The specified ability is not found. | 1154| 17700004 | The specified userId is invalid. | 1155| 17700026 | The specified bundle is disabled. | 1156| 17700029 | The specified ability is disabled. | 1157 1158**Example** 1159 1160```ts 1161import bundleManager from '@ohos.bundle.bundleManager'; 1162import { BusinessError } from '@ohos.base'; 1163import hilog from '@ohos.hilog'; 1164import Want from '@ohos.app.ability.Want'; 1165let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1166let userId = 100; 1167let want: Want = { 1168 bundleName : "com.example.myapplication", 1169 abilityName : "EntryAbility" 1170}; 1171 1172try { 1173 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => { 1174 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1175 }).catch((err: BusinessError) => { 1176 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1177 }); 1178} catch (err) { 1179 let message = (err as BusinessError).message; 1180 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1181} 1182``` 1183 1184```ts 1185import bundleManager from '@ohos.bundle.bundleManager'; 1186import { BusinessError } from '@ohos.base'; 1187import hilog from '@ohos.hilog'; 1188import Want from '@ohos.app.ability.Want'; 1189let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1190let want: Want = { 1191 bundleName : "com.example.myapplication", 1192 abilityName : "EntryAbility" 1193}; 1194 1195try { 1196 bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => { 1197 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1198 }).catch((err: BusinessError) => { 1199 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 1200 }) 1201} catch (err) { 1202 let message = (err as BusinessError).message; 1203 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 1204} 1205``` 1206 1207### bundleManager.queryAbilityInfoSync<sup>10+</sup> 1208 1209queryAbilityInfoSync(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> 1210 1211Obtains the ability information based on the given want, ability flags, and user ID. This API returns the result synchronously. 1212 1213**System API**: This is a system API. 1214 1215**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1216 1217**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1218 1219**Parameters** 1220 1221| Name | Type | Mandatory| Description | 1222| ------------ | ------ | ---- | ------------------------------------------------------- | 1223| want | Want | Yes | Want containing the bundle name to query. | 1224| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain.| 1225| 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. | 1226 1227**Return value** 1228 1229| Type | Description | 1230| ------------------------------------------------------------ | ------------------------------------ | 1231| Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | An array of ability information.| 1232 1233**Error codes** 1234 1235For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1236 1237| ID| Error Message | 1238| -------- | ------------------------------------- | 1239| 17700001 | The specified bundleName is not found. | 1240| 17700003 | The specified ability is not found. | 1241| 17700004 | The specified userId is invalid. | 1242| 17700026 | The specified bundle is disabled. | 1243| 17700029 | The specified ability is disabled. | 1244 1245**Example** 1246 1247```ts 1248import bundleManager from '@ohos.bundle.bundleManager'; 1249import { BusinessError } from '@ohos.base'; 1250import hilog from '@ohos.hilog'; 1251import Want from '@ohos.app.ability.Want'; 1252let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1253let userId = 100; 1254let want: Want = { 1255 bundleName : "com.example.myapplication", 1256 abilityName : "EntryAbility" 1257}; 1258 1259try { 1260 1261 let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags, userId); 1262 hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos)); 1263} catch (err) { 1264 let message = (err as BusinessError).message; 1265 hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message); 1266} 1267``` 1268 1269```ts 1270import bundleManager from '@ohos.bundle.bundleManager'; 1271import { BusinessError } from '@ohos.base'; 1272import hilog from '@ohos.hilog'; 1273import Want from '@ohos.app.ability.Want'; 1274let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 1275let want: Want = { 1276 bundleName : "com.example.myapplication", 1277 abilityName : "EntryAbility" 1278}; 1279 1280try { 1281 let infos = bundleManager.queryAbilityInfoSync(want, abilityFlags); 1282 hilog.info(0x0000, 'testTag', 'queryAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(infos)); 1283} catch (err) { 1284 let message = (err as BusinessError).message; 1285 hilog.error(0x0000, 'testTag', 'queryAbilityInfoSync failed. Cause: %{public}s', message); 1286} 1287``` 1288 1289### bundleManager.queryExtensionAbilityInfo 1290 1291queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId: number, callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void 1292 1293Obtains 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. 1294 1295**System API**: This is a system API. 1296 1297**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1298 1299**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1300 1301**Parameters** 1302 1303| Name | Type | Mandatory| Description | 1304| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1305| want | Want | Yes | Want containing the bundle name to query. | 1306| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the ExtensionAbility. | 1307| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the ExtensionAbility information to obtain. | 1308| userId | number | Yes | User ID. | 1309| 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.| 1310 1311**Error codes** 1312 1313For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1314 1315| ID| Error Message | 1316| -------- | ------------------------------------------- | 1317| 17700001 | The specified bundleName is not found. | 1318| 17700003 | The specified extensionAbility is not found. | 1319| 17700004 | The specified userId is invalid. | 1320| 17700026 | The specified bundle is disabled. | 1321 1322**Example** 1323 1324```ts 1325import bundleManager from '@ohos.bundle.bundleManager'; 1326import { BusinessError } from '@ohos.base'; 1327import hilog from '@ohos.hilog'; 1328import Want from '@ohos.app.ability.Want'; 1329let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1330let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1331let userId = 100; 1332let want: Want = { 1333 bundleName : "com.example.myapplication", 1334 abilityName : "EntryAbility" 1335}; 1336 1337try { 1338 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => { 1339 if (err) { 1340 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1341 } else { 1342 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1343 } 1344 }); 1345} catch (err) { 1346 let message = (err as BusinessError).message; 1347 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message); 1348} 1349``` 1350 1351### bundleManager.queryExtensionAbilityInfo 1352 1353queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void 1354 1355Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, and ExtensionAbility flags. This API uses an asynchronous callback to return the result. 1356 1357**System API**: This is a system API. 1358 1359**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1360 1361**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1362 1363**Parameters** 1364 1365| Name | Type | Mandatory| Description | 1366| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1367| want | Want | Yes | Want containing the bundle name to query. | 1368| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the ExtensionAbility. | 1369| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the ExtensionAbility information to obtain. | 1370| 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.| 1371 1372**Error codes** 1373 1374For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1375 1376| ID| Error Message | 1377| -------- | -------------------------------------------- | 1378| 17700001 | The specified bundleName is not found. | 1379| 17700003 | The specified extensionAbility is not found. | 1380| 17700026 | The specified bundle is disabled. | 1381 1382**Example** 1383 1384```ts 1385import bundleManager from '@ohos.bundle.bundleManager'; 1386import { BusinessError } from '@ohos.base'; 1387import hilog from '@ohos.hilog'; 1388import Want from '@ohos.app.ability.Want'; 1389let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1390let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1391let want: Want = { 1392 bundleName : "com.example.myapplication", 1393 abilityName : "EntryAbility" 1394}; 1395 1396try { 1397 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => { 1398 if (err) { 1399 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message); 1400 } else { 1401 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data)); 1402 } 1403 }); 1404} catch (err) { 1405 let message = (err as BusinessError).message; 1406 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', message); 1407} 1408``` 1409 1410### bundleManager.queryExtensionAbilityInfo 1411 1412queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> 1413 1414Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API uses a promise to return the result. 1415 1416**System API**: This is a system API. 1417 1418**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1419 1420**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1421 1422**Parameters** 1423 1424| Name | Type | Mandatory| Description | 1425| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1426| want | Want | Yes | Want containing the bundle name to query. | 1427| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the ExtensionAbility. | 1428| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the ExtensionAbility information to obtain.| 1429| 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. | 1430 1431**Return value** 1432 1433| Type | Description | 1434| ------------------------------------------------------------ | --------------------------------------------- | 1435| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Promise used to return the array of ExtensionAbility information obtained.| 1436 1437**Error codes** 1438 1439For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1440 1441| ID| Error Message | 1442| -------- | --------------------------------------| 1443| 17700001 | The specified bundleName is not found. | 1444| 17700003 | The specified extensionAbility is not found. | 1445| 17700004 | The specified userId is invalid. | 1446| 17700026 | The specified bundle is disabled. | 1447 1448**Example** 1449 1450```ts 1451import bundleManager from '@ohos.bundle.bundleManager'; 1452import { BusinessError } from '@ohos.base'; 1453import hilog from '@ohos.hilog'; 1454import Want from '@ohos.app.ability.Want'; 1455 1456let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1457let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1458let userId = 100; 1459let want: Want = { 1460 bundleName : "com.example.myapplication", 1461 abilityName : "EntryAbility" 1462}; 1463 1464try { 1465 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => { 1466 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1467 }).catch((err: BusinessError) => { 1468 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1469 }); 1470} catch (err) { 1471 let message = (err as BusinessError).message; 1472 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message); 1473} 1474``` 1475 1476```ts 1477import bundleManager from '@ohos.bundle.bundleManager'; 1478import { BusinessError } from '@ohos.base'; 1479import hilog from '@ohos.hilog'; 1480import Want from '@ohos.app.ability.Want'; 1481let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1482let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1483let want: Want = { 1484 bundleName : "com.example.myapplication", 1485 abilityName : "EntryAbility" 1486}; 1487 1488try { 1489 bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => { 1490 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data)); 1491 }).catch((err: BusinessError) => { 1492 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message); 1493 }) 1494} catch (err) { 1495 let message = (err as BusinessError).message; 1496 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', message); 1497} 1498``` 1499 1500### bundleManager.queryExtensionAbilityInfoSync<sup>10+</sup> 1501 1502queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> 1503 1504Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API returns the result synchronously. 1505 1506**System API**: This is a system API. 1507 1508**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1509 1510**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1511 1512**Parameters** 1513 1514| Name | Type | Mandatory| Description | 1515| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- | 1516| want | Want | Yes | Want containing the bundle name to query. | 1517| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the ExtensionAbility. | 1518| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the ExtensionAbility information to obtain.| 1519| 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. | 1520 1521**Return value** 1522 1523| Type | Description | 1524| ------------------------------------------------------------ | --------------------------------------------- | 1525| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | An array of ExtensionAbility information.| 1526 1527**Error codes** 1528 1529For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1530 1531| ID| Error Message | 1532| -------- | --------------------------------------| 1533| 17700001 | The specified bundleName is not found. | 1534| 17700003 | The specified extensionAbility is not found. | 1535| 17700004 | The specified userId is invalid. | 1536| 17700026 | The specified bundle is disabled. | 1537 1538**Example** 1539 1540```ts 1541import bundleManager from '@ohos.bundle.bundleManager'; 1542import { BusinessError } from '@ohos.base'; 1543import hilog from '@ohos.hilog'; 1544import Want from '@ohos.app.ability.Want'; 1545 1546let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1547let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1548let userId = 100; 1549let want: Want = { 1550 bundleName : "com.example.myapplication", 1551 abilityName : "EntryAbility" 1552}; 1553 1554try { 1555 let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId); 1556 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos)); 1557} catch (err) { 1558 let message = (err as BusinessError).message; 1559 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message); 1560} 1561``` 1562 1563```ts 1564import bundleManager from '@ohos.bundle.bundleManager'; 1565import { BusinessError } from '@ohos.base'; 1566import hilog from '@ohos.hilog'; 1567import Want from '@ohos.app.ability.Want'; 1568let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; 1569let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 1570let want: Want = { 1571 bundleName : "com.example.myapplication", 1572 abilityName : "EntryAbility" 1573}; 1574 1575try { 1576 let extenInfos = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags); 1577 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(extenInfos)); 1578} catch (err) { 1579 let message = (err as BusinessError).message; 1580 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed. Cause: %{public}s', message); 1581} 1582``` 1583 1584### bundleManager.getBundleNameByUid 1585 1586getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void 1587 1588Obtains the bundle name based on the given UID. This API uses an asynchronous callback to return the result. 1589 1590**System API**: This is a system API. 1591 1592**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1593 1594**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1595 1596**Parameters** 1597 1598| Name | Type | Mandatory| Description | 1599| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1600| uid | number | Yes | UID of the application. | 1601| 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.| 1602 1603**Error codes** 1604 1605For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1606 1607| ID| Error Message | 1608| -------- | --------------------- | 1609| 17700021 | The uid is not found. | 1610 1611**Example** 1612 1613```ts 1614import bundleManager from '@ohos.bundle.bundleManager'; 1615import { BusinessError } from '@ohos.base'; 1616import hilog from '@ohos.hilog'; 1617let uid = 20010005; 1618try { 1619 bundleManager.getBundleNameByUid(uid, (err, data) => { 1620 if (err) { 1621 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message); 1622 } else { 1623 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data)); 1624 } 1625 }); 1626} catch (err) { 1627 let message = (err as BusinessError).message; 1628 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', message); 1629} 1630``` 1631 1632### bundleManager.getBundleNameByUid 1633 1634getBundleNameByUid(uid: number): Promise\<string> 1635 1636Obtains the bundle name based on the given UID. This API uses a promise to return the result. 1637 1638**System API**: This is a system API. 1639 1640**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1641 1642**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1643 1644**Parameters** 1645 1646| Name| Type | Mandatory| Description | 1647| ---- | ------ | ---- | ------------------ | 1648| uid | number | Yes | UID of the application.| 1649 1650**Return value** 1651 1652| Type | Description | 1653| ---------------- | --------------------------- | 1654| Promise\<string> | Promise used to return the bundle name obtained.| 1655 1656**Error codes** 1657 1658For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1659 1660| ID| Error Message | 1661| -------- | ---------------------| 1662| 17700021 | The uid is not found. | 1663 1664**Example** 1665 1666```ts 1667import bundleManager from '@ohos.bundle.bundleManager'; 1668import { BusinessError } from '@ohos.base'; 1669import hilog from '@ohos.hilog'; 1670let uid = 20010005; 1671try { 1672 bundleManager.getBundleNameByUid(uid).then((data) => { 1673 hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data)); 1674 }).catch((err: BusinessError) => { 1675 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message); 1676 }); 1677} catch (err) { 1678 let message = (err as BusinessError).message; 1679 hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', message); 1680} 1681``` 1682 1683### bundleManager.getBundleNameByUidSync<sup>10+</sup> 1684 1685getBundleNameByUidSync(uid: number): string 1686 1687Obtains the bundle name based on the given UID. This API returns the result synchronously. 1688 1689**System API**: This is a system API. 1690 1691**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 1692 1693**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1694 1695**Parameters** 1696 1697| Name| Type | Mandatory| Description | 1698| ---- | ------ | ---- | ------------------ | 1699| uid | number | Yes | UID of the application.| 1700 1701**Return value** 1702 1703| Type | Description | 1704| ---------------- | --------------------------- | 1705| string | Bundle name obtained.| 1706 1707**Error codes** 1708 1709For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1710 1711| ID| Error Message | 1712| -------- | ---------------------| 1713| 17700021 | The uid is not found. | 1714 1715**Example** 1716 1717```ts 1718import bundleManager from '@ohos.bundle.bundleManager'; 1719import { BusinessError } from '@ohos.base'; 1720import hilog from '@ohos.hilog'; 1721let uid = 20010005; 1722try { 1723 let data = bundleManager.getBundleNameByUidSync(uid); 1724 hilog.info(0x0000, 'testTag', 'getBundleNameByUidSync successfully. Data: %{public}s', JSON.stringify(data)); 1725} catch (err) { 1726 let message = (err as BusinessError).message; 1727 hilog.error(0x0000, 'testTag', 'getBundleNameByUidSync failed. Cause: %{public}s', message); 1728} 1729``` 1730 1731### bundleManager.getBundleArchiveInfo 1732 1733getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void 1734 1735Obtains the bundle information based on the given HAP file path and bundle flags. This API uses an asynchronous callback to return the result. 1736 1737**System API**: This is a system API. 1738 1739**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1740 1741**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1742 1743**Parameters** 1744 1745| Name | Type | Mandatory| Description | 1746| ----------- | ------ | ---- | ----------------------------------------------------------- | 1747| hapFilePath | string | Yes | Path where the HAP file is stored. The path must be the relative path of the current bundle's data directory.| 1748| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 1749| 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.| 1750 1751**Error codes** 1752 1753For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1754 1755| ID| Error Message | 1756| -------- | --------------------------- | 1757| 17700022 | The hapFilePath is invalid. | 1758 1759**Example** 1760 1761```ts 1762import bundleManager from '@ohos.bundle.bundleManager'; 1763import { BusinessError } from '@ohos.base'; 1764import hilog from '@ohos.hilog'; 1765let hapFilePath = "/data/xxx/test.hap"; 1766let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1767 1768try { 1769 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => { 1770 if (err) { 1771 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1772 } else { 1773 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data)); 1774 } 1775 }); 1776} catch (err) { 1777 let message = (err as BusinessError).message; 1778 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message); 1779} 1780``` 1781 1782### bundleManager.getBundleArchiveInfo 1783 1784getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> 1785 1786Obtains the bundle information based on the given HAP file path and bundle flags. This API uses a promise to return the result. 1787 1788**System API**: This is a system API. 1789 1790**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1791 1792**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1793 1794**Parameters** 1795 1796| Name | Type | Mandatory| Description | 1797| ----------- | ------ | ---- | ------------------------------------------------------------ | 1798| hapFilePath | string | Yes | Path where the HAP file is stored. The path must be the relative path of the current bundle's data directory.| 1799| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 1800 1801**Return value** 1802 1803| Type | Description | 1804| ----------------------------------------------------------- | --------------------------- | 1805| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information obtained.| 1806 1807**Error codes** 1808 1809For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1810 1811| ID| Error Message | 1812| -------- | -------------------------- | 1813| 17700022 | The hapFilePath is invalid. | 1814 1815**Example** 1816 1817```ts 1818import bundleManager from '@ohos.bundle.bundleManager'; 1819import { BusinessError } from '@ohos.base'; 1820import hilog from '@ohos.hilog'; 1821let hapFilePath = "/data/xxx/test.hap"; 1822let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1823 1824try { 1825 bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => { 1826 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data)); 1827 }).catch((err: BusinessError) => { 1828 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message); 1829 }); 1830} catch (err) { 1831 let message = (err as BusinessError).message; 1832 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', message); 1833} 1834``` 1835 1836### bundleManager.getBundleArchiveInfoSync<sup>10+</sup> 1837 1838getBundleArchiveInfoSync(hapFilePath: string, bundleFlags: number): BundleInfo 1839 1840Obtains the bundle information based on the given HAP file path and bundle flags. This API returns the result synchronously. 1841 1842**System API**: This is a system API. 1843 1844**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 1845 1846**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1847 1848**Parameters** 1849 1850| Name | Type | Mandatory| Description | 1851| ----------- | ------ | ---- | ------------------------------------------------------------ | 1852| hapFilePath | string | Yes | Path where the HAP file is stored. The path must be the relative path of the current bundle's data directory.| 1853| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. | 1854 1855**Return value** 1856 1857| Type | Description | 1858| ----------------------------------------------------------- | --------------------------- | 1859| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.| 1860 1861**Error codes** 1862 1863For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1864 1865| ID| Error Message | 1866| -------- | -------------------------- | 1867| 17700022 | The hapFilePath is invalid. | 1868 1869**Example** 1870 1871```ts 1872import bundleManager from '@ohos.bundle.bundleManager'; 1873import { BusinessError } from '@ohos.base'; 1874import hilog from '@ohos.hilog'; 1875let hapFilePath = "/data/xxx/test.hap"; 1876let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 1877 1878try { 1879 let data = bundleManager.getBundleArchiveInfoSync(hapFilePath, bundleFlags) 1880 hilog.info(0x0000, 'testTag', 'getBundleArchiveInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 1881} catch (err) { 1882 let message = (err as BusinessError).message; 1883 hilog.error(0x0000, 'testTag', 'getBundleArchiveInfoSync failed. Cause: %{public}s', message); 1884} 1885``` 1886 1887### bundleManager.cleanBundleCacheFiles 1888 1889cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\<void>): void 1890 1891Clears the cache files based on the given bundle name. This API uses an asynchronous callback to return the result. 1892 1893**System API**: This is a system API. 1894 1895**Required permissions**: ohos.permission.REMOVE_CACHE_FILES 1896 1897**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1898 1899**Parameters** 1900 1901| Name | Type | Mandatory| Description | 1902| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 1903| bundleName | string | Yes | Bundle name. | 1904| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1905 1906**Error codes** 1907 1908For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1909 1910| ID| Error Message | 1911| -------- | ------------------------------------------------------------ | 1912| 17700001 | The specified bundleName is not found. | 1913| 17700030 | The specified bundle does not support clearing of cache files. | 1914 1915**Example** 1916 1917```ts 1918import bundleManager from '@ohos.bundle.bundleManager'; 1919import { BusinessError } from '@ohos.base'; 1920import hilog from '@ohos.hilog'; 1921let bundleName = "com.ohos.myapplication"; 1922 1923try { 1924 bundleManager.cleanBundleCacheFiles(bundleName, err => { 1925 if (err) { 1926 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1927 } else { 1928 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1929 } 1930 }); 1931} catch (err) { 1932 let message = (err as BusinessError).message; 1933 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 1934} 1935``` 1936 1937### bundleManager.cleanBundleCacheFiles 1938 1939cleanBundleCacheFiles(bundleName: string): Promise\<void> 1940 1941Clears the cache files based on the given bundle name. This API uses a promise to return the result. 1942 1943**System API**: This is a system API. 1944 1945**Required permissions**: ohos.permission.REMOVE_CACHE_FILES 1946 1947**System capability**: SystemCapability.BundleManager.BundleFramework.Core 1948 1949**Parameters** 1950 1951| Name | Type | Mandatory| Description | 1952| ---------- | ------ | ---- | ------------------------------------------ | 1953| bundleName | string | Yes | Bundle name.| 1954 1955**Return value** 1956 1957| Type | Description | 1958| -------------- | ------------------------------------------------------------ | 1959| Promise\<void> | Promise that returns no value. If clearing the cache files fails, an error object is thrown.| 1960 1961**Error codes** 1962 1963For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 1964 1965| ID| Error Message | 1966| -------- | ---------------------------------------------------------- | 1967| 17700001 | The specified bundleName is not found. | 1968| 17700030 | The specified bundle does not support clearing of cache files. | 1969 1970**Example** 1971 1972```ts 1973import bundleManager from '@ohos.bundle.bundleManager'; 1974import { BusinessError } from '@ohos.base'; 1975import hilog from '@ohos.hilog'; 1976let bundleName = "com.ohos.myapplication"; 1977 1978try { 1979 bundleManager.cleanBundleCacheFiles(bundleName).then(() => { 1980 hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.'); 1981 }).catch((err: BusinessError) => { 1982 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message); 1983 }); 1984} catch (err) { 1985 let message = (err as BusinessError).message; 1986 hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', message); 1987} 1988``` 1989 1990### bundleManager.setApplicationEnabled 1991 1992setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\<void>): void 1993 1994Enables or disables an application. This API uses an asynchronous callback to return the result. 1995 1996**System API**: This is a system API. 1997 1998**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE 1999 2000**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2001 2002**Parameters** 2003 2004| Name | Type | Mandatory| Description | 2005| ---------- | ------- | ---- | ------------------------------------- | 2006| bundleName | string | Yes | Bundle name. | 2007| isEnabled | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means to disable the application.| 2008| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2009 2010**Error codes** 2011 2012For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2013 2014| ID| Error Message | 2015| -------- | -------------------------------------- | 2016| 17700001 | The specified bundleName is not found. | 2017 2018**Example** 2019 2020```ts 2021import bundleManager from '@ohos.bundle.bundleManager'; 2022import { BusinessError } from '@ohos.base'; 2023import hilog from '@ohos.hilog'; 2024let bundleName = "com.ohos.myapplication"; 2025 2026try { 2027 bundleManager.setApplicationEnabled(bundleName, false, err => { 2028 if (err) { 2029 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2030 } else { 2031 hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.'); 2032 } 2033 }); 2034} catch (err) { 2035 let message = (err as BusinessError).message; 2036 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2037} 2038``` 2039 2040### bundleManager.setApplicationEnabled 2041 2042setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\<void> 2043 2044Enables or disables an application. This API uses a promise to return the result. 2045 2046**System API**: This is a system API. 2047 2048**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2049 2050**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2051 2052**Parameters** 2053 2054| Name | Type | Mandatory| Description | 2055| ---------- | ------- | ---- | ------------------------------------- | 2056| bundleName | string | Yes | Bundle name. | 2057| isEnabled | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means to disable the application.| 2058 2059**Return value** 2060 2061| Type | Description | 2062| -------------- | ------------------------------------ | 2063| Promise\<void> | Promise that returns no value.| 2064 2065**Error codes** 2066 2067For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2068 2069| ID| Error Message | 2070| -------- | -------------------------------------- | 2071| 17700001 | The specified bundleName is not found. | 2072 2073**Example** 2074 2075```ts 2076import bundleManager from '@ohos.bundle.bundleManager'; 2077import { BusinessError } from '@ohos.base'; 2078import hilog from '@ohos.hilog'; 2079let bundleName = "com.ohos.myapplication"; 2080 2081try { 2082 bundleManager.setApplicationEnabled(bundleName, false).then(() => { 2083 hilog.info(0x0000, "testTag", "setApplicationEnabled successfully."); 2084 }).catch((err: BusinessError) => { 2085 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message); 2086 }); 2087} catch (err) { 2088 let message = (err as BusinessError).message; 2089 hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', message); 2090} 2091``` 2092 2093### bundleManager.setApplicationEnabledSync<sup>10+</sup> 2094 2095setApplicationEnabledSync(bundleName: string, isEnabled: boolean): void 2096 2097Enables or disables an application. This API returns the result synchronously. 2098 2099**System API**: This is a system API. 2100 2101**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2102 2103**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2104 2105**Parameters** 2106 2107| Name | Type | Mandatory| Description | 2108| ---------- | ------- | ---- | ------------------------------------- | 2109| bundleName | string | Yes | Bundle name. | 2110| isEnabled | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means to disable the application.| 2111 2112**Error codes** 2113 2114For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2115 2116| ID| Error Message | 2117| -------- | -------------------------------------- | 2118| 17700001 | The specified bundleName is not found. | 2119 2120**Example** 2121 2122```ts 2123import bundleManager from '@ohos.bundle.bundleManager'; 2124import { BusinessError } from '@ohos.base'; 2125import hilog from '@ohos.hilog'; 2126let bundleName = "com.ohos.myapplication"; 2127 2128try { 2129 bundleManager.setApplicationEnabledSync(bundleName, false); 2130 hilog.info(0x0000, 'testTag', 'setApplicationEnabledSync successfully.'); 2131} catch (err) { 2132 let message = (err as BusinessError).message; 2133 hilog.error(0x0000, 'testTag', 'setApplicationEnabledSync failed: %{public}s', message); 2134} 2135``` 2136 2137### bundleManager.setAbilityEnabled 2138 2139setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean, callback: AsyncCallback\<void>): void 2140 2141Enables or disables an ability. This API uses an asynchronous callback to return the result. 2142 2143**System API**: This is a system API. 2144 2145**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2146 2147**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2148 2149**Parameters** 2150 2151| Name | Type | Mandatory| Description | 2152| -------- | ----------- | ---- | ------------------------------------- | 2153| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. | 2154| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.| 2155| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2156 2157**Error codes** 2158 2159For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2160 2161| ID| Error Message | 2162| -------- | ---------------------------------------| 2163| 17700001 | The specified bundleName is not found. | 2164| 17700003 | The specified abilityInfo is not found. | 2165 2166**Example** 2167 2168```ts 2169import bundleManager from '@ohos.bundle.bundleManager'; 2170import { BusinessError } from '@ohos.base'; 2171import hilog from '@ohos.hilog'; 2172import Want from '@ohos.app.ability.Want'; 2173let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2174let userId = 100; 2175let want: Want = { 2176 bundleName : "com.example.myapplication", 2177 abilityName : "EntryAbility" 2178}; 2179 2180try { 2181 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2182 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2183 let info = abilitiesInfo[0]; 2184 2185 bundleManager.setAbilityEnabled(info, false, err => { 2186 if (err) { 2187 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2188 } else { 2189 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2190 } 2191 }); 2192 }).catch((err: BusinessError) => { 2193 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2194 }); 2195} catch (err) { 2196 let message = (err as BusinessError).message; 2197 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2198} 2199``` 2200 2201### bundleManager.setAbilityEnabled 2202 2203setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): Promise\<void> 2204 2205Enables or disables an ability. This API uses a promise to return the result. 2206 2207**System API**: This is a system API. 2208 2209**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2210 2211**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2212 2213**Parameters** 2214 2215| Name | Type | Mandatory| Description | 2216| -------- | ----------- | ---- | ------------------------------------- | 2217| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. | 2218| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.| 2219 2220**Return value** 2221 2222| Type | Description | 2223| -------------- | --------------------------------- | 2224| Promise\<void> | Promise that returns no value.| 2225 2226**Error codes** 2227 2228For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2229 2230| ID| Error Message | 2231| -------- | -------------------------------------- | 2232| 17700001 | The specified bundleName is not found. | 2233| 17700003 | The specified abilityInfo is not found. | 2234 2235**Example** 2236 2237```ts 2238import bundleManager from '@ohos.bundle.bundleManager'; 2239import { BusinessError } from '@ohos.base'; 2240import hilog from '@ohos.hilog'; 2241import Want from '@ohos.app.ability.Want'; 2242let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2243let userId = 100; 2244let want: Want = { 2245 bundleName : "com.example.myapplication", 2246 abilityName : "EntryAbility" 2247}; 2248 2249try { 2250 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2251 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2252 let info = abilitiesInfo[0]; 2253 2254 bundleManager.setAbilityEnabled(info, false).then(() => { 2255 hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); 2256 }).catch((err: BusinessError) => { 2257 hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message); 2258 }); 2259 }).catch((err: BusinessError) => { 2260 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2261 }); 2262} catch (err) { 2263 let message = (err as BusinessError).message; 2264 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2265} 2266``` 2267 2268### bundleManager.setAbilityEnabledSync<sup>10+</sup> 2269 2270setAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): void 2271 2272Enables or disables an ability. This API returns the result synchronously. 2273 2274**System API**: This is a system API. 2275 2276**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE 2277 2278**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2279 2280**Parameters** 2281 2282| Name | Type | Mandatory| Description | 2283| -------- | ----------- | ---- | ------------------------------------- | 2284| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. | 2285| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.| 2286 2287**Error codes** 2288 2289For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2290 2291| ID| Error Message | 2292| -------- | ---------------------------------------| 2293| 17700001 | The specified bundleName is not found. | 2294| 17700003 | The specified abilityInfo is not found. | 2295 2296**Example** 2297 2298```ts 2299import bundleManager from '@ohos.bundle.bundleManager'; 2300import { BusinessError } from '@ohos.base'; 2301import hilog from '@ohos.hilog'; 2302import Want from '@ohos.app.ability.Want'; 2303let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2304let userId = 100; 2305let want: Want = { 2306 bundleName : "com.example.myapplication", 2307 abilityName : "EntryAbility" 2308}; 2309 2310try { 2311 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2312 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2313 let info = abilitiesInfo[0]; 2314 2315 try { 2316 bundleManager.setAbilityEnabledSync(info, false); 2317 hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully."); 2318 } catch (err) { 2319 let message = (err as BusinessError).message; 2320 hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', message); 2321 } 2322 }).catch((err: BusinessError) => { 2323 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2324 }); 2325} catch (err) { 2326 let message = (err as BusinessError).message; 2327 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2328} 2329``` 2330 2331### bundleManager.isApplicationEnabled 2332 2333isApplicationEnabled(bundleName: string, callback: AsyncCallback\<boolean>): void 2334 2335Checks whether an application is enabled. This API uses an asynchronous callback to return the result. 2336 2337**System API**: This is a system API. 2338 2339**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2340 2341**Parameters** 2342 2343| Name | Type | Mandatory| Description | 2344| ---------- | ------ | ---- | -------------------------- | 2345| bundleName | string | Yes | Bundle name.| 2346| callback | AsyncCallback\<boolean> | Yes| Callback used to return the result. The value **true** means that the application is enabled, and **false** means the opposite.| 2347 2348**Error codes** 2349 2350For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2351 2352| ID| Error Message | 2353| -------- | -------------------------------------- | 2354| 17700001 | The specified bundleName is not found. | 2355 2356**Example** 2357 2358```ts 2359import bundleManager from '@ohos.bundle.bundleManager'; 2360import { BusinessError } from '@ohos.base'; 2361import hilog from '@ohos.hilog'; 2362let bundleName = 'com.example.myapplication'; 2363 2364try { 2365 bundleManager.isApplicationEnabled(bundleName, (err, data) => { 2366 if (err) { 2367 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message); 2368 } else { 2369 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data)); 2370 } 2371 }); 2372} catch (err) { 2373 let message = (err as BusinessError).message; 2374 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', message); 2375} 2376``` 2377 2378### bundleManager.isApplicationEnabled 2379 2380isApplicationEnabled(bundleName: string): Promise\<boolean> 2381 2382Checks whether an application is enabled. This API uses a promise to return the result. 2383 2384**System API**: This is a system API. 2385 2386**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2387 2388**Parameters** 2389 2390| Name | Type | Mandatory| Description | 2391| ---------- | ------ | ---- | -------------------------- | 2392| bundleName | string | Yes | Bundle name. | 2393 2394**Return value** 2395 2396| Type | Description | 2397| ----------------- | ------------------------------------------------------------ | 2398| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is enabled, and **false** means the opposite.| 2399 2400**Error codes** 2401 2402For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2403 2404| ID| Error Message | 2405| -------- | -------------------------------------- | 2406| 17700001 | The specified bundleName is not found. | 2407 2408**Example** 2409 2410```ts 2411import bundleManager from '@ohos.bundle.bundleManager'; 2412import { BusinessError } from '@ohos.base'; 2413import hilog from '@ohos.hilog'; 2414let bundleName = 'com.example.myapplication'; 2415 2416try { 2417 bundleManager.isApplicationEnabled(bundleName).then((data) => { 2418 hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2419 }).catch((err: BusinessError) => { 2420 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message); 2421 }); 2422} catch (err) { 2423 let message = (err as BusinessError).message; 2424 hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', message); 2425} 2426``` 2427 2428### bundleManager.isApplicationEnabledSync<sup>10+</sup> 2429 2430isApplicationEnabledSync(bundleName: string): boolean 2431 2432Checks whether an application is enabled. This API returns the result synchronously. 2433 2434**System API**: This is a system API. 2435 2436**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2437 2438**Parameters** 2439 2440| Name | Type | Mandatory| Description | 2441| ---------- | ------ | ---- | -------------------------- | 2442| bundleName | string | Yes | Bundle name.| 2443 2444**Return value** 2445 2446| Type | Description | 2447| ------- | ------------------------------------------------------------ | 2448| boolean | Returns **true** if the application is enabled; returns **false** otherwise.| 2449 2450**Error codes** 2451 2452For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2453 2454| ID| Error Message | 2455| -------- | -------------------------------------- | 2456| 17700001 | The specified bundleName is not found. | 2457 2458**Example** 2459 2460```ts 2461import bundleManager from '@ohos.bundle.bundleManager'; 2462import { BusinessError } from '@ohos.base'; 2463import hilog from '@ohos.hilog'; 2464let bundleName = 'com.example.myapplication'; 2465 2466try { 2467 let data = bundleManager.isApplicationEnabledSync(bundleName); 2468 hilog.info(0x0000, 'testTag', 'isApplicationEnabledSync successfully: %{public}s', JSON.stringify(data)); 2469} catch (err) { 2470 let message = (err as BusinessError).message; 2471 hilog.error(0x0000, 'testTag', 'isApplicationEnabledSync failed: %{public}s', message); 2472} 2473``` 2474 2475### bundleManager.isAbilityEnabled 2476 2477isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), callback: AsyncCallback\<boolean>): void 2478 2479Checks whether an ability is enabled. This API uses an asynchronous callback to return the result. 2480 2481**System API**: This is a system API. 2482 2483**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2484 2485**Parameters** 2486 2487| Name| Type | Mandatory| Description | 2488| ---- | ----------- | ---- | --------------------------- | 2489| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability.| 2490| callback | AsyncCallback\<boolean> | Yes| Callback used to return the result. The value **true** means that the ability is enabled, and **false** means the opposite.| 2491 2492**Error codes** 2493 2494For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2495 2496| ID| Error Message | 2497| -------- | --------------------------------------- | 2498| 17700001 | The specified bundleName is not found. | 2499| 17700003 | The specified abilityName is not found. | 2500 2501**Example** 2502 2503```ts 2504import bundleManager from '@ohos.bundle.bundleManager'; 2505import { BusinessError } from '@ohos.base'; 2506import hilog from '@ohos.hilog'; 2507import Want from '@ohos.app.ability.Want'; 2508let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2509let userId = 100; 2510let want: Want = { 2511 bundleName : "com.example.myapplication", 2512 abilityName : "EntryAbility" 2513}; 2514 2515try { 2516 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2517 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2518 let info = abilitiesInfo[0]; 2519 2520 bundleManager.isAbilityEnabled(info, (err, data) => { 2521 if (err) { 2522 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message); 2523 } else { 2524 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data)); 2525 } 2526 }); 2527 }).catch((err: BusinessError) => { 2528 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2529 }); 2530} catch (err) { 2531 let message = (err as BusinessError).message; 2532 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2533} 2534``` 2535 2536### bundleManager.isAbilityEnabled 2537 2538isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Promise\<boolean> 2539 2540Checks whether an ability is enabled. This API uses a promise to return the result. 2541 2542**System API**: This is a system API. 2543 2544**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2545 2546**Parameters** 2547 2548| Name| Type | Mandatory| Description | 2549| ---- | ----------- | ---- | --------------------------- | 2550| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability.| 2551 2552**Return value** 2553 2554| Type | Description | 2555| ----------------- | ------------------------------------------------------------ | 2556| Promise\<boolean> | Promise used to return the result. The value **true** means that the ability is enabled, and **false** means the opposite.| 2557 2558**Error codes** 2559 2560For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2561 2562| ID| Error Message | 2563| -------- | --------------------------------------- | 2564| 17700001 | The specified bundleName is not found. | 2565| 17700003 | The specified abilityName is not found. | 2566 2567**Example** 2568 2569```ts 2570import bundleManager from '@ohos.bundle.bundleManager'; 2571import { BusinessError } from '@ohos.base'; 2572import hilog from '@ohos.hilog'; 2573import Want from '@ohos.app.ability.Want'; 2574let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2575let userId = 100; 2576let want: Want = { 2577 bundleName : "com.example.myapplication", 2578 abilityName : "EntryAbility" 2579}; 2580 2581try { 2582 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2583 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2584 let info = abilitiesInfo[0]; 2585 2586 bundleManager.isAbilityEnabled(info).then((data) => { 2587 hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data)); 2588 }).catch((err: BusinessError) => { 2589 hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message); 2590 }); 2591 }).catch((err: BusinessError) => { 2592 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2593 }); 2594} catch (err) { 2595 let message = (err as BusinessError).message; 2596 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2597} 2598``` 2599 2600### bundleManager.isAbilityEnabledSync<sup>10+</sup> 2601 2602isAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): boolean 2603 2604Checks whether an ability is enabled. This API returns the result synchronously. 2605 2606**System API**: This is a system API. 2607 2608**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2609 2610**Parameters** 2611 2612| Name| Type | Mandatory| Description | 2613| ---- | ----------- | ---- | --------------------------- | 2614| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability.| 2615 2616**Return value** 2617 2618| Type | Description | 2619| ------- | ------------------------------------------------------------------- | 2620| boolean | Returns **true** if the ability is enabled; returns **false** otherwise.| 2621 2622**Error codes** 2623 2624For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2625 2626| ID| Error Message | 2627| -------- | --------------------------------------- | 2628| 17700001 | The specified bundleName is not found. | 2629| 17700003 | The specified abilityName is not found. | 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 abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; 2639let userId = 100; 2640let want: Want = { 2641 bundleName : "com.example.myapplication", 2642 abilityName : "EntryAbility" 2643}; 2644 2645try { 2646 bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { 2647 hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); 2648 let info = abilitiesInfo[0]; 2649 2650 try { 2651 let data = bundleManager.isAbilityEnabledSync(info); 2652 hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data)); 2653 } catch (err) { 2654 let message = (err as BusinessError).message; 2655 hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', message); 2656 } 2657 }).catch((err: BusinessError) => { 2658 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); 2659 }); 2660} catch (err) { 2661 let message = (err as BusinessError).message; 2662 hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', message); 2663} 2664``` 2665 2666### bundleManager.getLaunchWantForBundle 2667 2668getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\<Want>): void 2669 2670Obtains 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. 2671 2672**System API**: This is a system API. 2673 2674**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2675 2676**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2677 2678**Parameters** 2679 2680| Name | Type | Mandatory| Description | 2681| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 2682| bundleName | string | Yes | Bundle name. | 2683| userId | number | Yes | User ID. | 2684| 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.| 2685 2686**Error codes** 2687 2688For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2689 2690| ID| Error Message | 2691| -------- | --------------------------------------| 2692| 17700001 | The specified bundleName is not found. | 2693| 17700004 | The specified user ID is not found. | 2694| 17700026 | The specified bundle is disabled. | 2695 2696**Example** 2697 2698```ts 2699import bundleManager from '@ohos.bundle.bundleManager'; 2700import { BusinessError } from '@ohos.base'; 2701import hilog from '@ohos.hilog'; 2702let bundleName = 'com.example.myapplication'; 2703let userId = 100; 2704 2705try { 2706 bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => { 2707 if (err) { 2708 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2709 } else { 2710 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 2711 } 2712 }); 2713} catch (err) { 2714 let message = (err as BusinessError).message; 2715 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message); 2716} 2717``` 2718 2719### bundleManager.getLaunchWantForBundle 2720 2721getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void 2722 2723Obtains the Want used to launch the bundle based on the given bundle name. This API uses an asynchronous callback to return the result. 2724 2725**System API**: This is a system API. 2726 2727**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2728 2729**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2730 2731**Parameters** 2732 2733| Name | Type | Mandatory| Description | 2734| ---------- | -------------------- | ---- | ------------------------------------------------------------ | 2735| bundleName | string | Yes | Bundle name. | 2736| 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.| 2737 2738**Error codes** 2739 2740For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2741 2742| ID| Error Message | 2743| -------- | --------------------------------------| 2744| 17700001 | The specified bundleName is not found. | 2745| 17700026 | The specified bundle is disabled. | 2746 2747**Example** 2748 2749```ts 2750import bundleManager from '@ohos.bundle.bundleManager'; 2751import { BusinessError } from '@ohos.base'; 2752import hilog from '@ohos.hilog'; 2753let bundleName = 'com.example.myapplication'; 2754 2755try { 2756 bundleManager.getLaunchWantForBundle(bundleName, (err, data) => { 2757 if (err) { 2758 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message); 2759 } else { 2760 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data)); 2761 } 2762 }); 2763} catch (err) { 2764 let message = (err as BusinessError).message; 2765 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', message); 2766} 2767``` 2768 2769### bundleManager.getLaunchWantForBundle 2770 2771getLaunchWantForBundle(bundleName: string, userId?: number): Promise\<Want> 2772 2773Obtains 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. 2774 2775**System API**: This is a system API. 2776 2777**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2778 2779**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2780 2781**Parameters** 2782 2783| Name | Type | Mandatory| Description | 2784| ---------- | ------ | ---- | ------------------------- | 2785| bundleName | string | Yes | Bundle name.| 2786| 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. | 2787 2788**Return value** 2789 2790| Type | Description | 2791| -------------- | ------------------------- | 2792| Promise\<Want> | Promise used to return the **Want** object obtained.| 2793 2794**Error codes** 2795 2796For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2797 2798| ID| Error Message | 2799| -------- | --------------------------------------| 2800| 17700001 | The specified bundleName is not found. | 2801| 17700004 | The specified user ID is not found. | 2802| 17700026 | The specified bundle is disabled. | 2803 2804**Example** 2805 2806```ts 2807import bundleManager from '@ohos.bundle.bundleManager'; 2808import { BusinessError } from '@ohos.base'; 2809import hilog from '@ohos.hilog'; 2810let bundleName = 'com.example.myapplication'; 2811let userId = 100; 2812 2813try { 2814 bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => { 2815 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data)); 2816 }).catch((err: BusinessError) => { 2817 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message); 2818 }); 2819} catch (err) { 2820 let message = (err as BusinessError).message; 2821 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', message); 2822} 2823``` 2824 2825 2826### bundleManager.getLaunchWantForBundleSync<sup>10+</sup> 2827 2828getLaunchWantForBundleSync(bundleName: string, userId?: number): Want 2829 2830Obtains the Want used to launch the bundle based on the given bundle name and user ID. This API returns the result synchronously. 2831 2832**System API**: This is a system API. 2833 2834**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 2835 2836**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2837 2838**Parameters** 2839 2840| Name | Type | Mandatory| Description | 2841| ---------- | ------ | ---- | ------------------------- | 2842| bundleName | string | Yes | Bundle name.| 2843| 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. | 2844 2845**Return value** 2846 2847| Type | Description | 2848| -------------- | ------------------------- | 2849| Want | **Want** object.| 2850 2851**Error codes** 2852 2853For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2854 2855| ID| Error Message | 2856| -------- | --------------------------------------| 2857| 17700001 | The specified bundleName is not found. | 2858| 17700004 | The specified user ID is not found. | 2859| 17700026 | The specified bundle is disabled. | 2860 2861**Example** 2862 2863```ts 2864import bundleManager from '@ohos.bundle.bundleManager'; 2865import { BusinessError } from '@ohos.base'; 2866import hilog from '@ohos.hilog'; 2867import Want from '@ohos.app.ability.Want'; 2868let bundleName = 'com.example.myapplication'; 2869let userId = 100; 2870 2871try { 2872 let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName, userId); 2873 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); 2874} catch (err) { 2875 let message = (err as BusinessError).message; 2876 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message); 2877} 2878``` 2879 2880```ts 2881import bundleManager from '@ohos.bundle.bundleManager'; 2882import { BusinessError } from '@ohos.base'; 2883import hilog from '@ohos.hilog'; 2884import Want from '@ohos.app.ability.Want'; 2885let bundleName = 'com.example.myapplication'; 2886let userId = 100; 2887 2888try { 2889 let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName); 2890 hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); 2891} catch (err) { 2892 let message = (err as BusinessError).message; 2893 hilog.error(0x0000, 'testTag', 'getLaunchWantForBundleSync failed. Cause: %{public}s', message); 2894} 2895``` 2896 2897### bundleManager.getProfileByAbility 2898 2899getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void 2900 2901Obtains the JSON strings of the profile based on the given module name, ability name, and metadata name. This API uses an asynchronous callback to return the result. 2902 2903> **NOTE** 2904> 2905> If the profile uses the resource reference format, the return value retains this format (for example, **$string:res_id**). You can obtain the referenced resources through related APIs of the resource management module. 2906 2907**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2908 2909**Parameters** 2910 2911| Name | Type | Mandatory| Description | 2912| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 2913| moduleName | string | Yes | Module name. | 2914| abilityName | string | Yes | Ability name. | 2915| metadataName | string | Yes | Metadata name. | 2916| callback | AsyncCallback<Array\<string>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of JSON strings obtained. Otherwise, **err** is an error object.| 2917 2918**Error codes** 2919 2920For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2921 2922| ID| Error Message | 2923| -------- | ------------------------------------------------------------ | 2924| 17700002 | The specified moduleName is not existed. | 2925| 17700003 | The specified abilityName is not existed. | 2926| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2927| 17700026 | The specified bundle is disabled. | 2928| 17700029 | The specified ability is disabled. | 2929 2930**Example** 2931 2932```ts 2933import bundleManager from '@ohos.bundle.bundleManager'; 2934import { BusinessError } from '@ohos.base'; 2935import hilog from '@ohos.hilog'; 2936let moduleName = 'entry'; 2937let abilityName = 'EntryAbility'; 2938let metadataName = 'com.example.myapplication.metadata'; 2939 2940try { 2941 bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => { 2942 if (err) { 2943 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 2944 } else { 2945 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data)); 2946 } 2947 }); 2948} catch (err) { 2949 let message = (err as BusinessError).message; 2950 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message); 2951} 2952``` 2953 2954### bundleManager.getProfileByAbility 2955 2956getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string\>\> 2957 2958Obtains the JSON strings of the profile based on the given module name, ability name, and metadata name. This API uses a promise to return the result. 2959 2960> **NOTE** 2961> 2962> If the profile uses the resource reference format, the return value retains this format (for example, **$string:res_id**). You can obtain the referenced resources through related APIs of the resource management module. 2963 2964**System capability**: SystemCapability.BundleManager.BundleFramework.Core 2965 2966**Parameters** 2967 2968| Name | Type | Mandatory| Description | 2969| ------------ | ------ | ---- | -------------------------- | 2970| moduleName | string | Yes | Module name. | 2971| abilityName | string | Yes | Ability name. | 2972| metadataName | string | No | Metadata name. By default, no value is passed.| 2973 2974**Return value** 2975 2976| Type | Description | 2977| ----------------------- | ------------------------------- | 2978| Promise<Array\<string>> | Promise used to return the array of JSON strings obtained.| 2979 2980**Error codes** 2981 2982For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 2983 2984| ID| Error Message | 2985| -------- | ------------------------------------------------------------ | 2986| 17700002 | The specified moduleName is not existed. | 2987| 17700003 | The specified abilityName is not existed. | 2988| 17700024 | Failed to get the profile because there is no profile in the HAP. | 2989| 17700026 | The specified bundle is disabled. | 2990| 17700029 | The specified ability is disabled. | 2991 2992**Example** 2993 2994```ts 2995import bundleManager from '@ohos.bundle.bundleManager'; 2996import { BusinessError } from '@ohos.base'; 2997import hilog from '@ohos.hilog'; 2998let moduleName = 'entry'; 2999let abilityName = 'EntryAbility'; 3000 3001try { 3002 bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => { 3003 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data)); 3004 }).catch((err: BusinessError) => { 3005 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 3006 }); 3007} catch (err) { 3008 let message = (err as BusinessError).message; 3009 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message); 3010} 3011``` 3012 3013```ts 3014import bundleManager from '@ohos.bundle.bundleManager'; 3015import { BusinessError } from '@ohos.base'; 3016import hilog from '@ohos.hilog'; 3017let moduleName = 'entry'; 3018let abilityName = 'EntryAbility'; 3019let metadataName = 'com.example.myapplication.metadata'; 3020try { 3021 bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => { 3022 hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data)); 3023 }).catch((err: BusinessError) => { 3024 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message); 3025 }); 3026} catch (err) { 3027 let message = (err as BusinessError).message; 3028 hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message); 3029} 3030``` 3031 3032### bundleManager.getProfileByAbilitySync<sup>10+</sup> 3033 3034getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array\<string\> 3035 3036Obtains the JSON strings of the profile based on the given module name, ability name, and metadata name. This API returns the result synchronously. 3037 3038> **NOTE** 3039> 3040> If the profile uses the resource reference format, the return value retains this format (for example, **$string:res_id**). You can obtain the referenced resources through related APIs of the resource management module. 3041 3042**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3043 3044**Parameters** 3045 3046| Name | Type | Mandatory| Description | 3047| ------------ | ------ | ---- | -------------------------- | 3048| moduleName | string | Yes | Module name. | 3049| abilityName | string | Yes | Ability name. | 3050| metadataName | string | No | Metadata name. By default, no value is passed.| 3051 3052**Return value** 3053 3054| Type | Description | 3055| ----------------------- | ------------------------------- | 3056| Array\<string> | An array of JSON strings.| 3057 3058**Error codes** 3059 3060For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3061 3062| ID| Error Message | 3063| -------- | ------------------------------------------------------------ | 3064| 17700002 | The specified moduleName is not existed. | 3065| 17700003 | The specified abilityName is not existed. | 3066| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3067| 17700026 | The specified bundle is disabled. | 3068| 17700029 | The specified ability is disabled. | 3069 3070**Example** 3071 3072```ts 3073import bundleManager from '@ohos.bundle.bundleManager'; 3074import { BusinessError } from '@ohos.base'; 3075import hilog from '@ohos.hilog'; 3076let moduleName = 'entry'; 3077let abilityName = 'EntryAbility'; 3078 3079try { 3080 let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName); 3081 hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3082} catch (err) { 3083 let message = (err as BusinessError).message; 3084 hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message); 3085} 3086``` 3087 3088```ts 3089import bundleManager from '@ohos.bundle.bundleManager'; 3090import { BusinessError } from '@ohos.base'; 3091import hilog from '@ohos.hilog'; 3092let moduleName: string = 'entry'; 3093let abilityName: string = 'EntryAbility'; 3094let metadataName: string = 'com.example.myapplication.metadata'; 3095try { 3096 let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName, metadataName); 3097 hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3098} catch (err) { 3099 let message = (err as BusinessError).message; 3100 hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message); 3101} 3102``` 3103 3104### bundleManager.getProfileByExtensionAbility 3105 3106getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void 3107 3108Obtains the JSON strings of the profile based on the given module name, ExtensionAbility name, and metadata name. This API uses an asynchronous callback to return the result. 3109 3110> **NOTE** 3111> 3112> If the profile uses the resource reference format, the return value retains this format (for example, **$string:res_id**). You can obtain the referenced resources through related APIs of the resource management module. 3113 3114**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3115 3116**Parameters** 3117 3118| Name | Type | Mandatory| Description | 3119| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ | 3120| moduleName | string | Yes | Module name. | 3121| extensionAbilityName | string | Yes | ExtensionAbility name. | 3122| metadataName | string | Yes | Metadata name. | 3123| callback | AsyncCallback<Array\<string>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of JSON strings obtained. Otherwise, **err** is an error object.| 3124 3125**Error codes** 3126 3127For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3128 3129| ID| Error Message | 3130| -------- | ------------------------------------------------------------ | 3131| 17700002 | The specified moduleName is not existed. | 3132| 17700003 | The specified extensionAbilityName not existed. | 3133| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3134| 17700026 | The specified bundle is disabled. | 3135 3136**Example** 3137 3138```ts 3139import bundleManager from '@ohos.bundle.bundleManager'; 3140import { BusinessError } from '@ohos.base'; 3141import hilog from '@ohos.hilog'; 3142let moduleName = 'entry'; 3143let extensionAbilityName = 'com.example.myapplication.extension'; 3144let metadataName = 'com.example.myapplication.metadata'; 3145 3146try { 3147 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => { 3148 if (err) { 3149 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message); 3150 } else { 3151 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data)); 3152 } 3153 }); 3154} catch (err) { 3155 let message = (err as BusinessError).message; 3156 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', message); 3157} 3158``` 3159 3160### bundleManager.getProfileByExtensionAbility 3161 3162getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string\>\> 3163 3164Obtains the JSON strings of the profile based on the given module name, ExtensionAbility name, and metadata name. This API uses a promise to return the result. 3165 3166> **NOTE** 3167> 3168> If the profile uses the resource reference format, the return value retains this format (for example, **$string:res_id**). You can obtain the referenced resources through related APIs of the resource management module. 3169 3170**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3171 3172**Parameters** 3173 3174| Name | Type | Mandatory| Description | 3175| -------------------- | ------ | ---- | ---------------------------------- | 3176| moduleName | string | Yes | Module name. | 3177| extensionAbilityName | string | Yes | ExtensionAbility name.| 3178| metadataName | string | No | Metadata name. By default, no value is passed. | 3179 3180**Return value** 3181 3182| Type | Description | 3183| ----------------------- | ----------------------------------- | 3184| Promise<Array\<string>> | Promise used to return the array of JSON strings obtained.| 3185 3186**Error codes** 3187 3188For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3189 3190| ID| Error Message | 3191| -------- | ------------------------------------------------------------ | 3192| 17700002 | The specified moduleName is not existed. | 3193| 17700003 | The specified extensionAbilityName not existed. | 3194| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3195| 17700026 | The specified bundle is disabled. | 3196 3197**Example** 3198 3199```ts 3200import bundleManager from '@ohos.bundle.bundleManager'; 3201import { BusinessError } from '@ohos.base'; 3202import hilog from '@ohos.hilog'; 3203let moduleName = 'entry'; 3204let extensionAbilityName = 'com.example.myapplication.extension'; 3205let metadataName = 'com.example.myapplication.metadata'; 3206 3207try { 3208 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => { 3209 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data)); 3210 }).catch((err: BusinessError) => { 3211 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 3212 }); 3213} catch (err) { 3214 let message = (err as BusinessError).message; 3215 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message); 3216} 3217 3218try { 3219 bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => { 3220 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data)); 3221 }).catch((err: BusinessError) => { 3222 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message); 3223 }); 3224} catch (err) { 3225 let message = (err as BusinessError).message; 3226 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message); 3227} 3228``` 3229 3230### bundleManager.getProfileByExtensionAbilitySync<sup>10+</sup> 3231 3232getProfileByExtensionAbilitySync(moduleName: string, extensionAbilityName: string, metadataName?: string): Array\<string\> 3233 3234Obtains the JSON strings of the profile based on the given module name, ExtensionAbility name, and metadata name. This API returns the result synchronously. 3235 3236> **NOTE** 3237> 3238> If the profile uses the resource reference format, the return value retains this format (for example, **$string:res_id**). You can obtain the referenced resources through related APIs of the resource management module. 3239 3240**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3241 3242**Parameters** 3243 3244| Name | Type | Mandatory| Description | 3245| -------------------- | ------ | ---- | ---------------------------------- | 3246| moduleName | string | Yes | Module name. | 3247| extensionAbilityName | string | Yes | ExtensionAbility name.| 3248| metadataName | string | No | Metadata name. By default, no value is passed. | 3249 3250**Return value** 3251 3252| Type | Description | 3253| ----------------------- | ----------------------------------- | 3254| Array\<string> | An array of JSON strings.| 3255 3256**Error codes** 3257 3258For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3259 3260| ID| Error Message | 3261| -------- | ------------------------------------------------------------ | 3262| 17700002 | The specified moduleName is not existed. | 3263| 17700003 | The specified extensionAbilityName not existed. | 3264| 17700024 | Failed to get the profile because there is no profile in the HAP. | 3265| 17700026 | The specified bundle is disabled. | 3266 3267**Example** 3268 3269```ts 3270import bundleManager from '@ohos.bundle.bundleManager'; 3271import { BusinessError } from '@ohos.base'; 3272import hilog from '@ohos.hilog'; 3273let moduleName = 'entry'; 3274let extensionAbilityName = 'com.example.myapplication.extension'; 3275let metadataName = 'com.example.myapplication.metadata'; 3276 3277try { 3278 let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName); 3279 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3280} catch (err) { 3281 let message = (err as BusinessError).message; 3282 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message); 3283} 3284 3285try { 3286 let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName, metadataName); 3287 hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data)); 3288} catch (err) { 3289 let message = (err as BusinessError).message; 3290 hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message); 3291} 3292``` 3293 3294### bundleManager.getPermissionDef 3295 3296getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void 3297 3298Obtains the **PermissionDef** struct based on the given permission name. This API uses an asynchronous callback to return the result. 3299 3300**System API**: This is a system API. 3301 3302**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3303 3304**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3305 3306**Parameters** 3307 3308| Name | Type | Mandatory| Description | 3309| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3310| permissionName | string | Yes | Name of the permission. | 3311| callback | AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.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.| 3312 3313**Error codes** 3314 3315For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3316 3317| ID| Error Message | 3318| -------- | ------------------------------------- | 3319| 17700006 | The specified permission is not found. | 3320 3321**Example** 3322 3323```ts 3324import bundleManager from '@ohos.bundle.bundleManager'; 3325import { BusinessError } from '@ohos.base'; 3326import hilog from '@ohos.hilog'; 3327let permission = "ohos.permission.GET_BUNDLE_INFO"; 3328try { 3329 bundleManager.getPermissionDef(permission, (err, data) => { 3330 if (err) { 3331 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message); 3332 } else { 3333 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data)); 3334 } 3335 }); 3336} catch (err) { 3337 let message = (err as BusinessError).message; 3338 hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', message); 3339} 3340``` 3341 3342### bundleManager.getPermissionDef 3343 3344getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> 3345 3346Obtains the **PermissionDef** struct based on the given permission name. This API uses a promise to return the result. 3347 3348**System API**: This is a system API. 3349 3350**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3351 3352**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3353 3354**Parameters** 3355 3356| Name | Type | Mandatory| Description | 3357| -------------- | ------ | ---- | -------------- | 3358| permissionName | string | Yes | Name of the permission.| 3359 3360**Return value** 3361 3362| Type | Description | 3363| ------------------------------------------------------------ | ------------------------------------------ | 3364| Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | Promise used to return the **PermissionDef** object obtained.| 3365 3366**Error codes** 3367 3368For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3369 3370| ID| Error Message | 3371| -------- | ------------------------------------- | 3372| 17700006 | The specified permission is not found. | 3373 3374**Example** 3375 3376```ts 3377import bundleManager from '@ohos.bundle.bundleManager'; 3378import { BusinessError } from '@ohos.base'; 3379import hilog from '@ohos.hilog'; 3380let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 3381try { 3382 bundleManager.getPermissionDef(permissionName).then((data) => { 3383 hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data)); 3384 }).catch((err: BusinessError) => { 3385 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message); 3386 }); 3387} catch (err) { 3388 let message = (err as BusinessError).message; 3389 hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', message); 3390} 3391``` 3392 3393### bundleManager.getPermissionDefSync<sup>10+</sup> 3394 3395getPermissionDefSync(permissionName: string): [PermissionDef](js-apis-bundleManager-permissionDef.md); 3396 3397Obtains the **PermissionDef** struct based on the given permission name. This API returns the result synchronously. 3398 3399**System API**: This is a system API. 3400 3401**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3402 3403**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3404 3405**Parameters** 3406 3407| Name | Type | Mandatory| Description | 3408| -------------- | ------ | ---- | -------------- | 3409| permissionName | string | Yes | Name of the permission.| 3410 3411**Return value** 3412 3413| Type | Description | 3414| ------------------------------------------------------------ | ------------------------------------------ | 3415|[PermissionDef](js-apis-bundleManager-permissionDef.md) | **PermissionDef** object.| 3416 3417**Error codes** 3418 3419For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3420 3421| ID| Error Message | 3422| -------- | ------------------------------------- | 3423| 17700006 | The specified permission is not found. | 3424 3425**Example** 3426 3427```ts 3428import bundleManager from '@ohos.bundle.bundleManager'; 3429import { BusinessError } from '@ohos.base'; 3430import hilog from '@ohos.hilog'; 3431let permissionName = "ohos.permission.GET_BUNDLE_INFO"; 3432try { 3433 let PermissionDef = bundleManager.getPermissionDefSync(permissionName); 3434 hilog.info(0x0000, 'testTag', 'getPermissionDefSync successfully. Data: %{public}s', JSON.stringify(PermissionDef)); 3435} catch (err) { 3436 let message = (err as BusinessError).message; 3437 hilog.error(0x0000, 'testTag', 'getPermissionDefSync failed. Cause: %{public}s', message); 3438} 3439``` 3440 3441### bundleManager.getAbilityLabel 3442 3443getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<string>): void 3444 3445Obtains the ability label based on the given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result. 3446 3447**System API**: This is a system API. 3448 3449**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3450 3451**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 3452 3453**Parameters** 3454 3455| Name | Type | Mandatory| Description | 3456| ----------- | ---------------------- | ---- | ------------------------------------------------------------ | 3457| bundleName | string | Yes | Bundle name. | 3458| moduleName | string | Yes | Module name. | 3459| abilityName | string | Yes | Ability name. | 3460| 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.| 3461 3462**Error codes** 3463 3464For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3465 3466| ID| Error Message | 3467| -------- | -------------------------------------- | 3468| 17700001 | The specified bundleName is not found. | 3469| 17700002 | The specified moduleName is not found. | 3470| 17700003 | The specified abilityName is not found. | 3471| 17700026 | The specified bundle is disabled. | 3472| 17700029 | The specified ability is disabled. | 3473 3474**Example** 3475 3476```ts 3477import bundleManager from '@ohos.bundle.bundleManager'; 3478import { BusinessError } from '@ohos.base'; 3479import hilog from '@ohos.hilog'; 3480let bundleName = 'com.example.myapplication'; 3481let moduleName = 'entry'; 3482let abilityName = 'EntryAbility'; 3483 3484try { 3485 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => { 3486 if (err) { 3487 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message); 3488 } else { 3489 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data)); 3490 } 3491 }); 3492} catch (err) { 3493 let message = (err as BusinessError).message; 3494 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', message); 3495} 3496``` 3497 3498### bundleManager.getAbilityLabel 3499 3500getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string> 3501 3502Obtains the ability label based on the given bundle name, module name, and ability name. This API uses a promise to return the result. 3503 3504**System API**: This is a system API. 3505 3506**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3507 3508**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 3509 3510**Parameters** 3511 3512| Name | Type | Mandatory| Description | 3513| ----------- | ------ | ---- | ------------------------- | 3514| bundleName | string | Yes | Bundle name. | 3515| moduleName | string | Yes | Module name. | 3516| abilityName | string | Yes | Ability name.| 3517 3518**Return value** 3519 3520| Type | Description | 3521| ---------------- | ----------------------------------- | 3522| Promise\<string> | Promise used to return the label.| 3523 3524**Error codes** 3525 3526For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3527 3528| ID| Error Message | 3529| -------- | --------------------------------------- | 3530| 17700001 | The specified bundleName is not found. | 3531| 17700002 | The specified moduleName is not found. | 3532| 17700003 | The specified abilityName is not found. | 3533| 17700026 | The specified bundle is disabled. | 3534| 17700029 | The specified ability is disabled. | 3535 3536**Example** 3537 3538```ts 3539import bundleManager from '@ohos.bundle.bundleManager'; 3540import { BusinessError } from '@ohos.base'; 3541import hilog from '@ohos.hilog'; 3542let bundleName = 'com.example.myapplication'; 3543let moduleName = 'entry'; 3544let abilityName = 'EntryAbility'; 3545 3546try { 3547 bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => { 3548 hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data)); 3549 }).catch((err: BusinessError) => { 3550 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message); 3551 }); 3552} catch (err) { 3553 let message = (err as BusinessError).message; 3554 hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', message); 3555} 3556``` 3557 3558### bundleManager.getAbilityLabelSync<sup>10+</sup> 3559 3560getAbilityLabelSync(bundleName: string, moduleName: string, abilityName: string): string 3561 3562Obtains the ability label based on the given bundle name, module name, and ability name. This API returns the result synchronously. 3563 3564**System API**: This is a system API. 3565 3566**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3567 3568**System capability**: SystemCapability.BundleManager.BundleFramework.Resource 3569 3570**Parameters** 3571 3572| Name | Type | Mandatory| Description | 3573| ----------- | ------ | ---- | ------------------------- | 3574| bundleName | string | Yes | Bundle name. | 3575| moduleName | string | Yes | Module name. | 3576| abilityName | string | Yes | Ability name.| 3577 3578**Return value** 3579 3580| Type | Description | 3581| ---------------- | ----------------------------------- | 3582| string | Label of the ability.| 3583 3584**Error codes** 3585 3586For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3587 3588| ID| Error Message | 3589| -------- | --------------------------------------- | 3590| 17700001 | The specified bundleName is not found. | 3591| 17700002 | The specified moduleName is not found. | 3592| 17700003 | The specified abilityName is not found. | 3593| 17700026 | The specified bundle is disabled. | 3594| 17700029 | The specified ability is disabled. | 3595 3596**Example** 3597 3598```ts 3599import bundleManager from '@ohos.bundle.bundleManager'; 3600import { BusinessError } from '@ohos.base'; 3601import hilog from '@ohos.hilog'; 3602let bundleName = 'com.example.myapplication'; 3603let moduleName = 'entry'; 3604let abilityName = 'EntryAbility'; 3605 3606try { 3607 let abilityLabel = bundleManager.getAbilityLabelSync(bundleName, moduleName, abilityName); 3608 hilog.info(0x0000, 'testTag', 'getAbilityLabelSync successfully. Data: %{public}s', abilityLabel); 3609} catch (err) { 3610 let message = (err as BusinessError).message; 3611 hilog.error(0x0000, 'testTag', 'getAbilityLabelSync failed. Cause: %{public}s', message); 3612} 3613``` 3614 3615### bundleManager.getApplicationInfoSync 3616 3617getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) 3618 3619Obtains the application information based on the given bundle name, application flags, and user ID. This API returns the result synchronously. 3620 3621**System API**: This is a system API. 3622 3623**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3624 3625**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3626 3627**Parameters** 3628 3629| Name | Type | Mandatory| Description | 3630| ----------- | ------ | ---- | ----------------------------------------------------------| 3631| bundleName | string | Yes | Bundle name. | 3632| applicationFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. | 3633| userId | number | Yes | User ID. | 3634 3635**Return value** 3636 3637| Type | Description | 3638| --------------- | ------------------------- | 3639| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Application information obtained.| 3640 3641**Error codes** 3642 3643For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3644 3645| ID| Error Message | 3646| -------- | -------------------------------------- | 3647| 17700001 | The specified bundleName is not found. | 3648| 17700004 | The specified user ID is not found. | 3649| 17700026 | The specified bundle is disabled. | 3650 3651**Example** 3652 3653```ts 3654import bundleManager from '@ohos.bundle.bundleManager'; 3655import { BusinessError } from '@ohos.base'; 3656import hilog from '@ohos.hilog'; 3657let bundleName = 'com.example.myapplication'; 3658let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 3659let userId = 100; 3660 3661try { 3662 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId); 3663 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 3664} catch (err) { 3665 let message = (err as BusinessError).message; 3666 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message); 3667} 3668``` 3669 3670### bundleManager.getApplicationInfoSync 3671 3672getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) 3673 3674Obtains the application information based on the given bundle name and application flags. This API returns the result synchronously. 3675 3676**System API**: This is a system API. 3677 3678**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3679 3680**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3681 3682**Parameters** 3683 3684| Name | Type | Mandatory| Description | 3685| ---------------- | -------------------------- | ---- | ----------------------------------------------------- | 3686| bundleName | string | Yes | Bundle name. | 3687| applicationFlags | [number](#applicationflag) | Yes | Type of the application information to obtain.| 3688 3689**Return value** 3690 3691| Type | Description | 3692| ----------------------------------------------------------- | ------------------------- | 3693| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Application information obtained.| 3694 3695**Error codes** 3696 3697For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3698 3699| ID| Error Message | 3700| -------- | -------------------------------------- | 3701| 17700001 | The specified bundleName is not found. | 3702| 17700026 | The specified bundle is disabled. | 3703 3704**Example** 3705 3706```ts 3707import bundleManager from '@ohos.bundle.bundleManager'; 3708import { BusinessError } from '@ohos.base'; 3709import hilog from '@ohos.hilog'; 3710let bundleName = 'com.example.myapplication'; 3711let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT; 3712 3713try { 3714 let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags); 3715 hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data)); 3716} catch (err) { 3717 let message = (err as BusinessError).message; 3718 hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', message); 3719} 3720``` 3721 3722### bundleManager.getBundleInfoSync 3723 3724getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md) 3725 3726Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API returns the result synchronously. 3727 3728**System API**: This is a system API. 3729 3730**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3731 3732**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3733 3734**Parameters** 3735 3736| Name | Type | Mandatory| Description | 3737| ----------- | ------ | ---- | -------------------------------------------------------- | 3738| bundleName | string | Yes | Bundle name. | 3739| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 3740| userId | number | Yes | User ID. | 3741 3742**Return value** 3743 3744| Type | Description | 3745| ---------- | -------------------- | 3746| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.| 3747 3748**Error codes** 3749 3750For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3751 3752| ID| Error Message | 3753| -------- | ------------------------------------- | 3754| 17700001 | The specified bundleName is not found. | 3755| 17700004 | The specified user ID is not found. | 3756| 17700026 | The specified bundle is disabled. | 3757 3758**Example** 3759 3760```ts 3761import bundleManager from '@ohos.bundle.bundleManager'; 3762import { BusinessError } from '@ohos.base'; 3763import hilog from '@ohos.hilog'; 3764let bundleName = 'com.example.myapplication'; 3765let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 3766let userId = 100; 3767 3768try { 3769 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId); 3770 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 3771} catch (err) { 3772 let message = (err as BusinessError).message; 3773 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message); 3774} 3775``` 3776 3777### bundleManager.getBundleInfoSync 3778 3779getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md) 3780 3781Obtains the bundle information based on the given bundle name and bundle flags. This API returns the result synchronously. 3782 3783**System API**: This is a system API. 3784 3785**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 3786 3787**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3788 3789**Parameters** 3790 3791| Name | Type | Mandatory| Description | 3792| ----------- | --------------------- | ---- | ------------------------------------------------------ | 3793| bundleName | string | Yes | Bundle name. | 3794| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 3795 3796**Return value** 3797 3798| Type | Description | 3799| ------------------------------------------------- | -------------------- | 3800| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.| 3801 3802**Error codes** 3803 3804For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3805 3806| ID| Error Message | 3807| -------- | -------------------------------------- | 3808| 17700001 | The specified bundleName is not found. | 3809| 17700026 | The specified bundle is disabled. | 3810 3811**Example** 3812 3813```ts 3814import bundleManager from '@ohos.bundle.bundleManager'; 3815import { BusinessError } from '@ohos.base'; 3816import hilog from '@ohos.hilog'; 3817let bundleName = 'com.example.myapplication'; 3818let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 3819try { 3820 let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags); 3821 hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data)); 3822} catch (err) { 3823 let message = (err as BusinessError).message; 3824 hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message); 3825} 3826``` 3827 3828### bundleManager.getSharedBundleInfo<sup>10+</sup> 3829 3830getSharedBundleInfo(bundleName: string, moduleName: string, callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void 3831 3832Obtains the shared bundle information based on the given bundle name. This API uses an asynchronous callback to return the result. 3833 3834**System API**: This is a system API. 3835 3836**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3837 3838**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3839 3840**Parameters** 3841 3842| Name | Type | Mandatory| Description | 3843| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3844| bundleName | string | Yes | Bundle name. | 3845| moduleName | string | Yes | Module name. | 3846| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the shared bundle information obtained.| 3847 3848**Error codes** 3849 3850For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3851 3852| ID| Error Message | 3853| -------- | -------------------------------------- | 3854| 17700001 | The specified bundleName is not found. | 3855| 17700002 | The specified moduleName is not found. | 3856 3857**Example** 3858 3859```ts 3860import bundleManager from '@ohos.bundle.bundleManager'; 3861import { BusinessError } from '@ohos.base'; 3862import hilog from '@ohos.hilog'; 3863let bundleName = 'com.example.myapplication'; 3864let moduleName = 'library'; 3865 3866try { 3867 bundleManager.getSharedBundleInfo(bundleName, moduleName, (err, data) => { 3868 if (err) { 3869 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', err.message); 3870 } else { 3871 hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully: %{public}s', JSON.stringify(data)); 3872 } 3873 }); 3874} catch (err) { 3875 let message = (err as BusinessError).message; 3876 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', message); 3877} 3878``` 3879 3880### bundleManager.getSharedBundleInfo<sup>10+</sup> 3881 3882getSharedBundleInfo(bundleName: string, moduleName: string): Promise\<Array\<SharedBundleInfo\>\> 3883 3884Obtains the shared bundle information based on the given bundle name. This API uses a promise to return the result. 3885 3886**System API**: This is a system API. 3887 3888**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3889 3890**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3891 3892**Parameters** 3893 3894| Name | Type | Mandatory| Description | 3895| ---------- | ------ | ---- | -------------------------- | 3896| bundleName | string | Yes | Bundle name.| 3897| moduleName | string | Yes | Module name.| 3898 3899**Return value** 3900 3901| Type | Description | 3902| ------------------------------------------------------------ | ----------------------------------- | 3903| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Promise used to return the shared bundle information obtained.| 3904 3905**Error codes** 3906 3907For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 3908 3909| ID| Error Message | 3910| -------- | -------------------------------------- | 3911| 17700001 | The specified bundleName is not found. | 3912| 17700002 | The specified moduleName is not found. | 3913 3914**Example** 3915 3916```ts 3917import bundleManager from '@ohos.bundle.bundleManager'; 3918import { BusinessError } from '@ohos.base'; 3919import hilog from '@ohos.hilog'; 3920let bundleName = 'com.example.myapplication'; 3921let moduleName = 'library'; 3922 3923try { 3924 bundleManager.getSharedBundleInfo(bundleName, moduleName).then((data) => { 3925 hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 3926 }).catch((err: BusinessError) => { 3927 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', err.message); 3928 }); 3929} catch (err) { 3930 let message = (err as BusinessError).message; 3931 hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', message); 3932} 3933``` 3934 3935### bundleManager.getAllSharedBundleInfo<sup>10+</sup> 3936 3937getAllSharedBundleInfo(callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void 3938 3939Obtains the information about all shared bundles. This API uses an asynchronous callback to return the result. 3940 3941**System API**: This is a system API. 3942 3943**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3944 3945**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3946 3947**Parameters** 3948 3949| Name | Type | Mandatory| Description | 3950| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3951| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.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.| 3952 3953**Example** 3954 3955```ts 3956import bundleManager from '@ohos.bundle.bundleManager'; 3957import { BusinessError } from '@ohos.base'; 3958import hilog from '@ohos.hilog'; 3959 3960try { 3961 bundleManager.getAllSharedBundleInfo((err, data) => { 3962 if (err) { 3963 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', err.message); 3964 } else { 3965 hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully: %{public}s', JSON.stringify(data)); 3966 } 3967 }); 3968} catch (err) { 3969 let message = (err as BusinessError).message; 3970 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', message); 3971} 3972``` 3973 3974### bundleManager.getAllSharedBundleInfo<sup>10+</sup> 3975 3976getAllSharedBundleInfo(): Promise\<Array\<SharedBundleInfo\>\> 3977 3978Obtains the information about all shared bundles. This API uses a promise to return the result. 3979 3980**System API**: This is a system API. 3981 3982**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 3983 3984**System capability**: SystemCapability.BundleManager.BundleFramework.Core 3985 3986**Return value** 3987 3988| Type | Description | 3989| ------------------------------------------------------------ | ----------------------------------- | 3990| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Promise used to return an array of the shared bundle information obtained.| 3991 3992**Example** 3993 3994```ts 3995import bundleManager from '@ohos.bundle.bundleManager'; 3996import { BusinessError } from '@ohos.base'; 3997import hilog from '@ohos.hilog'; 3998 3999try { 4000 bundleManager.getAllSharedBundleInfo().then((data) => { 4001 hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data)); 4002 }).catch((err: BusinessError) => { 4003 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', err.message); 4004 }); 4005} catch (err) { 4006 let message = (err as BusinessError).message; 4007 hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', message); 4008} 4009``` 4010 4011### bundleManager.getAppProvisionInfo<sup>10+</sup> 4012 4013getAppProvisionInfo(bundleName: string, callback: AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\>): void 4014 4015Obtains the provision profile based on the given bundle name. This API uses an asynchronous callback to return the result. 4016 4017**System API**: This is a system API. 4018 4019**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4020 4021**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4022 4023**Parameters** 4024 4025| Name | Type | Mandatory| Description | 4026| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4027| bundleName | string | Yes | Bundle name.| 4028| callback | AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the provision profile obtained.| 4029 4030**Error codes** 4031 4032For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4033 4034| ID| Error Message | 4035| -------- | -------------------------------------- | 4036| 17700001 | The specified bundleName is not found. | 4037 4038**Example** 4039 4040```ts 4041import bundleManager from '@ohos.bundle.bundleManager'; 4042import { BusinessError } from '@ohos.base'; 4043import hilog from '@ohos.hilog'; 4044let bundleName = "com.ohos.myapplication"; 4045 4046try { 4047 bundleManager.getAppProvisionInfo(bundleName, (err, data) => { 4048 if (err) { 4049 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message); 4050 } else { 4051 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data)); 4052 } 4053 }); 4054} catch (err) { 4055 let message = (err as BusinessError).message; 4056 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message); 4057} 4058``` 4059 4060### bundleManager.getAppProvisionInfo<sup>10+</sup> 4061 4062getAppProvisionInfo(bundleName: string, userId: number, callback: AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\>): void 4063 4064Obtains the provision profile based on the given bundle name and user ID. This API uses an asynchronous callback to return the result. 4065 4066**System API**: This is a system API. 4067 4068**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4069 4070**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4071 4072**Parameters** 4073 4074| Name | Type | Mandatory| Description | 4075| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4076| bundleName | string | Yes | Bundle name.| 4077| userId | number | Yes| User ID, which can be obtained by calling [getOsAccountLocalId](js-apis-osAccount.md#getosaccountlocalid9).| 4078| callback | AsyncCallback\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the provision profile obtained.| 4079 4080 4081**Error codes** 4082 4083For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4084 4085| ID| Error Message | 4086| -------- | -------------------------------------- | 4087| 17700001 | The specified bundleName is not found. | 4088| 17700004 | The specified user ID is not found. | 4089 4090**Example** 4091 4092```ts 4093import bundleManager from '@ohos.bundle.bundleManager'; 4094import { BusinessError } from '@ohos.base'; 4095import hilog from '@ohos.hilog'; 4096let bundleName = "com.ohos.myapplication"; 4097let userId = 100; 4098 4099try { 4100 bundleManager.getAppProvisionInfo(bundleName, userId, (err, data) => { 4101 if (err) { 4102 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', err.message); 4103 } else { 4104 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully: %{public}s', JSON.stringify(data)); 4105 } 4106 }); 4107} catch (err) { 4108 let message = (err as BusinessError).message; 4109 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed: %{public}s', message); 4110} 4111``` 4112 4113### bundleManager.getAppProvisionInfo<sup>10+</sup> 4114 4115getAppProvisionInfo(bundleName: string, userId?: number): Promise\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> 4116 4117Obtains the provision profile based on the given bundle name and user ID. This API uses a promise to return the result. 4118 4119**System API**: This is a system API. 4120 4121**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4122 4123**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4124 4125**Parameters** 4126 4127| Name | Type | Mandatory| Description | 4128| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4129| bundleName | string | Yes| Bundle name.| 4130| 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](js-apis-osAccount.md#getosaccountlocalid9) to obtain the user ID on the current device.| 4131 4132 4133**Return value** 4134 4135| Type | Description | 4136| ------------------------------------------------------------ | ----------------------------------- | 4137| Promise\<[AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md)\> | Promise used to return the provision profile obtained.| 4138 4139**Error codes** 4140 4141For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4142 4143| ID| Error Message | 4144| -------- | -------------------------------------- | 4145| 17700001 | The specified bundleName is not found. | 4146| 17700004 | The specified user ID is not found. | 4147 4148**Example** 4149 4150```ts 4151import bundleManager from '@ohos.bundle.bundleManager'; 4152import { BusinessError } from '@ohos.base'; 4153import hilog from '@ohos.hilog'; 4154let bundleName = "com.ohos.myapplication"; 4155let userId = 100; 4156 4157try { 4158 bundleManager.getAppProvisionInfo(bundleName).then((data) => { 4159 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data)); 4160 }).catch((err: BusinessError) => { 4161 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message); 4162 }); 4163} catch (err) { 4164 let message = (err as BusinessError).message; 4165 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message); 4166} 4167 4168try { 4169 bundleManager.getAppProvisionInfo(bundleName, userId).then((data) => { 4170 hilog.info(0x0000, 'testTag', 'getAppProvisionInfo successfully. Data: %{public}s', JSON.stringify(data)); 4171 }).catch((err: BusinessError) => { 4172 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', err.message); 4173 }); 4174} catch (err) { 4175 let message = (err as BusinessError).message; 4176 hilog.error(0x0000, 'testTag', 'getAppProvisionInfo failed. Cause: %{public}s', message); 4177} 4178``` 4179 4180### bundleManager.getAppProvisionInfoSync<sup>10+</sup> 4181 4182getAppProvisionInfoSync(bundleName: string, userId?: number): AppProvisionInfo 4183 4184Obtains the provision profile based on the given bundle name and user ID. This API returns the result synchronously. 4185 4186**System API**: This is a system API. 4187 4188**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4189 4190**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4191 4192**Parameters** 4193 4194| Name | Type | Mandatory| Description | 4195| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4196| bundleName | string | Yes| Bundle name.| 4197| 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](js-apis-osAccount.md#getosaccountlocalid9) to obtain the user ID on the current device.| 4198 4199 4200**Return value** 4201 4202| Type | Description | 4203| ------------------------------------------------------------ | ----------------------------------- | 4204| [AppProvisionInfo](js-apis-bundleManager-AppProvisionInfo.md) | Provision profile.| 4205 4206**Error codes** 4207 4208For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4209 4210| ID| Error Message | 4211| -------- | -------------------------------------- | 4212| 17700001 | The specified bundleName is not found. | 4213| 17700004 | The specified user ID is not found. | 4214 4215**Example** 4216 4217```ts 4218import bundleManager from '@ohos.bundle.bundleManager'; 4219import { BusinessError } from '@ohos.base'; 4220import hilog from '@ohos.hilog'; 4221let bundleName = "com.ohos.myapplication"; 4222let userId = 100; 4223 4224try { 4225 let data = bundleManager.getAppProvisionInfoSync(bundleName); 4226 hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4227} catch (err) { 4228 let message = (err as BusinessError).message; 4229 hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message); 4230} 4231 4232try { 4233 let data = bundleManager.getAppProvisionInfoSync(bundleName, userId); 4234 hilog.info(0x0000, 'testTag', 'getAppProvisionInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4235} catch (err) { 4236 let message = (err as BusinessError).message; 4237 hilog.error(0x0000, 'testTag', 'getAppProvisionInfoSync failed. Cause: %{public}s', message); 4238} 4239``` 4240 4241### bundleManager.getSpecifiedDistributionType<sup>10+</sup> 4242getSpecifiedDistributionType(bundleName: string): string 4243 4244Obtains the distribution type of a bundle in synchronous mode. The return value is the **specifiedDistributionType** field value in [InstallParam](./js-apis-installer.md#installparam) passed when **install** is called. 4245 4246**System API**: This is a system API. 4247 4248**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4249 4250**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4251 4252**Parameters** 4253 4254| Name | Type | Mandatory| Description | 4255| -------------- | ----------------------------------- | ---- | ---------------------------- | 4256| bundleName | string | Yes | Bundle name.| 4257 4258**Return value** 4259 4260| Type | Description | 4261| ------------- | -------------------------------------- | 4262| string | Distribution type of the bundle.| 4263 4264**Error codes** 4265 4266For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4267 4268| ID| Error Message | 4269| -------- | ------------------------------------------------------------ | 4270| 17700001 | The specified bundleName is not found. | 4271 4272**Example** 4273```ts 4274import bundleManager from '@ohos.bundle.bundleManager'; 4275import { BusinessError } from '@ohos.base'; 4276let bundleName = "com.example.myapplication"; 4277 4278try { 4279 let type = bundleManager.getSpecifiedDistributionType(bundleName); 4280 console.info('getSpecifiedDistributionType successfully, type:' + type); 4281} catch (error) { 4282 let message = (error as BusinessError).message; 4283 console.error('getSpecifiedDistributionType failed. Cause: ' + message); 4284} 4285``` 4286 4287 4288### bundleManager.getAdditionalInfo<sup>10+</sup> 4289 4290getAdditionalInfo(bundleName: string): string 4291 4292Obtains additional information about a bundle in synchronous mode. The return value is the **additionalInfo** field value in [InstallParam](./js-apis-installer.md#installparam) passed when **install** is called. 4293 4294**System API**: This is a system API. 4295 4296**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4297 4298**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4299 4300**Parameters** 4301 4302| Name | Type | Mandatory| Description | 4303| -------------- | ----------------------------------- | ---- | ---------------------------- | 4304| bundleName | string | Yes | Bundle name.| 4305 4306**Return value** 4307 4308| Type | Description | 4309| ------------- | -------------------------------------- | 4310| string | Additional information about the bundle.| 4311 4312**Error codes** 4313 4314For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4315 4316| ID| Error Message | 4317| -------- | ------------------------------------------------------------ | 4318| 17700001 | The specified bundleName is not found. | 4319 4320**Example** 4321 4322```ts 4323import bundleManager from '@ohos.bundle.bundleManager'; 4324import { BusinessError } from '@ohos.base'; 4325let bundleName = "com.example.myapplication"; 4326 4327try { 4328 let info = bundleManager.getAdditionalInfo(bundleName); 4329 console.info('getAdditionalInfo successfully, additionInfo:' + info); 4330} catch (error) { 4331 let message = (error as BusinessError).message; 4332 console.error('getAdditionalInfo failed. Cause: ' + message); 4333} 4334``` 4335 4336### bundleManager.getBundleInfoForSelfSync<sup>10+</sup> 4337 4338getBundleInfoForSelfSync(bundleFlags: number): BundleInfo 4339 4340Obtains the bundle information of this bundle based on the given bundle flags in synchronous mode. 4341 4342**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4343 4344**Parameters** 4345 4346| Name | Type | Mandatory| Description | 4347| ----------- | ------ | ---- | --------------------- | 4348| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.| 4349 4350**Return value** 4351 4352| Type | Description | 4353| ------------------------------------------------- | -------------------- | 4354| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.| 4355 4356**Example** 4357 4358```ts 4359import bundleManager from '@ohos.bundle.bundleManager'; 4360import { BusinessError } from '@ohos.base'; 4361import hilog from '@ohos.hilog'; 4362let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION; 4363try { 4364 let data = bundleManager.getBundleInfoForSelfSync(bundleFlags); 4365 hilog.info(0x0000, 'testTag', 'getBundleInfoForSelfSync successfully: %{public}s', JSON.stringify(data)); 4366} catch (err) { 4367 let message = (err as BusinessError).message; 4368 hilog.error(0x0000, 'testTag', 'getBundleInfoForSelfSync failed: %{public}s', message); 4369} 4370``` 4371 4372### bundleManager.queryExtensionAbilityInfoSync<sup>11+</sup> 4373 4374queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: string, extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> 4375 4376Obtains the ExtensionAbility information based on the given want, ExtensionAbility type, ExtensionAbility flags, and user ID. This API returns the result synchronously. 4377 4378**System API**: This is a system API. 4379 4380**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 4381 4382**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4383 4384**Parameters** 4385 4386| Name | Type | Mandatory| Description | 4387| --------------------- | ------------------------------- | ---- | --------------------------------------------------------- | 4388| want | Want | Yes | Want containing the bundle name to query. | 4389| extensionAbilityType | string | Yes | Type of the custom ExtensionAbility. | 4390| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Information flags to be contained in the returned **ExtensionAbilityInfo** object.| 4391| 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.| 4392 4393**Return value** 4394 4395| Type | Description | 4396| ------------------------------------------------------------ | -------------------------------------- | 4397| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | An array of **ExtensionAbilityInfo** objects.| 4398 4399**Error codes** 4400 4401For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4402 4403| ID| Error Message | 4404| -------- | -------------------------------------------- | 4405| 17700001 | The specified bundleName is not found. | 4406| 17700003 | The specified extensionAbility is not found. | 4407| 17700004 | The specified userId is invalid. | 4408| 17700026 | The specified bundle is disabled. | 4409 4410**Example** 4411 4412```ts 4413// Call the API with the userId parameter specified. 4414import bundleManager from '@ohos.bundle.bundleManager'; 4415import hilog from '@ohos.hilog'; 4416import Want from '@ohos.app.ability.Want'; 4417import { BusinessError } from '@ohos.base'; 4418 4419let extensionAbilityType = "form"; 4420let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4421let userId = 100; 4422let want: Want = { 4423 bundleName : "com.example.myapplication", 4424 abilityName : "EntryAbility" 4425}; 4426 4427try { 4428 let data = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags, userId) 4429 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4430} catch (err) { 4431 let message = (err as BusinessError).message; 4432 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4433} 4434``` 4435 4436```ts 4437// Call the API without passing in the userId parameter. 4438import bundleManager from '@ohos.bundle.bundleManager'; 4439import hilog from '@ohos.hilog'; 4440import Want from '@ohos.app.ability.Want'; 4441import { BusinessError } from '@ohos.base'; 4442 4443let extensionAbilityType = "form"; 4444let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4445let want: Want = { 4446 bundleName : "com.example.myapplication", 4447 abilityName : "EntryAbility" 4448}; 4449 4450try { 4451 let data = bundleManager.queryExtensionAbilityInfoSync(want, extensionAbilityType, extensionFlags); 4452 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4453} catch (err) { 4454 let message = (err as BusinessError).message; 4455 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4456} 4457``` 4458 4459### bundleManager.getJsonProfile<sup>11+</sup> 4460 4461getJsonProfile(profileType: [ProfileType](#profiletype11), bundleName: string, moduleName?: string): string 4462 4463Obtains the JSON strings of the profile based on the given profile type, bundle name, and module name. This API returns the result synchronously. 4464 4465No permission is required for obtaining the caller's own profile. 4466 4467**System API**: This is a system API. 4468 4469**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 4470 4471**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4472 4473**Parameters** 4474 4475| Name | Type | Mandatory| Description | 4476| --------------------- | ------------------------------- | ---- | --------------------------------------------------------- | 4477| profileType | [ProfileType](#profiletype11) | Yes | Type of the profile. | 4478| bundleName | string | Yes | Bundle name of the application. | 4479| moduleName | string | No | Module name of the application. If this parameter is not passed in, the entry module is used. | 4480 4481**Return value** 4482 4483| Type | Description | 4484| ------ | ------------------------ | 4485| string | JSON string of the profile.| 4486 4487**Error codes** 4488 4489For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4490 4491| ID| Error Message | 4492| -------- | -------------------------------------------- | 4493| 17700001 | The specified bundleName is not found. | 4494| 17700002 | The specified moduleName is not found. | 4495| 17700024 | Failed to get the profile because the specified profile is not found in the HAP. | 4496| 17700026 | The specified bundle is disabled. | 4497 4498**Example** 4499 4500```ts 4501import bundleManager from '@ohos.bundle.bundleManager'; 4502import hilog from '@ohos.hilog'; 4503import { BusinessError } from '@ohos.base'; 4504 4505let bundleName = 'com.example.myapplication'; 4506let moduleName = 'entry'; 4507let profileType = bundleManager.ProfileType.INTENT_PROFILE; 4508 4509try { 4510 let data = bundleManager.getJsonProfile(profileType, bundleName, moduleName) 4511 hilog.info(0x0000, 'testTag', 'getJsonProfile successfully. Data: %{public}s', data); 4512} catch (err) { 4513 let message = (err as BusinessError).message; 4514 hilog.error(0x0000, 'testTag', 'getJsonProfile failed: %{public}s', message); 4515} 4516``` 4517 4518### bundleManager.getRecoverableApplicationInfo<sup>11+</sup> 4519 4520getRecoverableApplicationInfo(callback: AsyncCallback\<Array\<RecoverableApplicationInfo\>\>): void 4521 4522Obtains information about all preinstalled applications that can be restored. This API uses an asynchronous callback to return the result. 4523 4524**System API**: This is a system API. 4525 4526**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4527 4528**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4529 4530**Parameters** 4531 4532| Name | Type | Mandatory| Description | 4533| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4534| callback | AsyncCallback\<Array\<[RecoverableApplicationInfo](js-apis-bundleManager-recoverableApplicationInfo.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.| 4535 4536**Example** 4537 4538```ts 4539import bundleManager from '@ohos.bundle.bundleManager'; 4540import { BusinessError } from '@ohos.base'; 4541import hilog from '@ohos.hilog'; 4542 4543try { 4544 bundleManager.getRecoverableApplicationInfo((err, data) => { 4545 if (err) { 4546 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', err.message); 4547 } else { 4548 hilog.info(0x0000, 'testTag', 'getRecoverableApplicationInfo successfully: %{public}s', JSON.stringify(data)); 4549 } 4550 }); 4551} catch (err) { 4552 let message = (err as BusinessError).message; 4553 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', message); 4554} 4555``` 4556 4557### bundleManager.getRecoverableApplicationInfo<sup>11+</sup> 4558 4559getRecoverableApplicationInfo(): Promise\<Array\<RecoverableApplicationInfo\>\> 4560 4561Obtains information about all preinstalled applications that can be restored. This API uses a promise to return the result. 4562 4563**System API**: This is a system API. 4564 4565**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4566 4567**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4568 4569**Return value** 4570 4571| Type | Description | 4572| ------------------------------------------------------------ | ----------------------------------- | 4573| Promise\<Array\<[RecoverableApplicationInfo](js-apis-bundleManager-recoverableApplicationInfo.md)\>\> | Promise used to return the information about all recoverable applications.| 4574 4575**Example** 4576 4577```ts 4578import bundleManager from '@ohos.bundle.bundleManager'; 4579import { BusinessError } from '@ohos.base'; 4580import hilog from '@ohos.hilog'; 4581 4582try { 4583 bundleManager.getRecoverableApplicationInfo().then((data) => { 4584 hilog.info(0x0000, 'testTag', 'getRecoverableApplicationInfo successfully: %{public}s', JSON.stringify(data)); 4585 }).catch((err: BusinessError) => { 4586 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', err.message); 4587 }); 4588} catch (err) { 4589 let message = (err as BusinessError).message; 4590 hilog.error(0x0000, 'testTag', 'getRecoverableApplicationInfo failed: %{public}s', message); 4591} 4592``` 4593 4594### bundleManager.setAdditionalInfo<sup>11+</sup> 4595 4596setAdditionalInfo(bundleName: string, additionalInfo: string): void 4597 4598Sets additional information for an application. This API can be called only by AppGallery. 4599 4600**System API**: This is a system API. 4601 4602**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 4603 4604**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4605 4606**Parameters** 4607 4608| Name | Type | Mandatory| Description | 4609| --------------------- | ------------------------------- | ---- | -------------------------------------------------- | 4610| bundleName | string | Yes | Bundle name. | 4611| additionalInfo | string | Yes | Additional information to set. | 4612 4613**Error codes** 4614 4615For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4616 4617| ID| Error Message | 4618| -------- | ---------------------------------------------------------- | 4619| 17700001 | The specified bundleName is not found. | 4620| 17700053 | Not app gallery call. | 4621 4622**Example** 4623 4624```ts 4625import bundleManager from '@ohos.bundle.bundleManager'; 4626import { BusinessError } from '@ohos.base'; 4627import hilog from '@ohos.hilog'; 4628 4629let bundleName = "com.example.myapplication"; 4630let additionalInfo = "xxxxxxxxx,formUpdateLevel:4"; 4631 4632try { 4633 bundleManager.setAdditionalInfo(bundleName, additionalInfo); 4634 hilog.info(0x0000, 'testTag', 'setAdditionalInfo successfully.'); 4635} catch (err) { 4636 let message = (err as BusinessError).message; 4637 hilog.error(0x0000, 'testTag', 'setAdditionalInfo failed. Cause: %{public}s', message); 4638} 4639``` 4640 4641### bundleManager.verifyAbc<sup>11+</sup> 4642 4643verifyAbc(abcPaths: Array\<string>, deleteOriginalFiles: boolean, callback: AsyncCallback\<void>): void 4644 4645Verifies an .abc file. This API uses an asynchronous callback to return the result. 4646 4647**Required permissions**: ohos.permission.RUN_DYN_CODE 4648 4649**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4650 4651**Parameters** 4652 4653| Name | Type | Mandatory| Description | 4654| ----------- | ------ | ---- | ---------------------------- | 4655| abcPaths | Array\<string> | Yes | Path of the .abc file.| 4656| deleteOriginalFiles | boolean | Yes | Whether to delete the .abc file. The value **true** means to delete the file, and **false** means the opposite.| 4657| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the verification is successful, **err** is **undefined**; otherwise, **err** is an error object.| 4658 4659**Error codes** 4660 4661For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4662 4663| ID| Error Message | 4664| -------- | ------------------------------------- | 4665| 17700201 | verifyAbc failed. | 4666 4667**Example** 4668 4669```ts 4670import bundleManager from '@ohos.bundle.bundleManager'; 4671import { BusinessError } from '@ohos.base'; 4672import hilog from '@ohos.hilog'; 4673let abcPaths : Array<string> = ['/data/storage/el2/base/a.abc']; 4674 4675try { 4676 bundleManager.verifyAbc(abcPaths, true, (err, data) => { 4677 if (err) { 4678 hilog.error(0x0000, 'testTag', 'verifyAbc failed: %{public}s', err.message); 4679 } else { 4680 hilog.info(0x0000, 'testTag', 'verifyAbc successfully'); 4681 } 4682 }); 4683} catch (err) { 4684 let message = (err as BusinessError).message; 4685 hilog.error(0x0000, 'testTag', 'verifyAbc failed: %{public}s', message); 4686} 4687``` 4688 4689### bundleManager.verifyAbc<sup>11+</sup> 4690 4691verifyAbc(abcPaths: Array\<string>, deleteOriginalFiles: boolean): Promise\<void> 4692 4693Verifies an .abc file. This API uses a promise to return the result. 4694 4695**Required permissions**: ohos.permission.RUN_DYN_CODE 4696 4697**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4698 4699**Parameters** 4700 4701| Name | Type | Mandatory| Description | 4702| ----------- | ------ | ---- | ---------------------------- | 4703| abcPaths | Array\<string> | Yes | Path of the .abc file.| 4704| deleteOriginalFiles | boolean | Yes | Whether to delete the .abc file. The value **true** means to delete the file, and **false** means the opposite. | 4705 4706**Return value** 4707 4708| Type | Description | 4709| ----------------------------------------------------------- | --------------------------- | 4710| Promise\<void> | Promise that returns no value.| 4711 4712**Error codes** 4713 4714For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4715 4716| ID| Error Message | 4717| -------- | --------------------------------------| 4718| 17700201 | verifyAbc failed. | 4719 4720**Example** 4721 4722```ts 4723import bundleManager from '@ohos.bundle.bundleManager'; 4724import { BusinessError } from '@ohos.base'; 4725import hilog from '@ohos.hilog'; 4726let abcPaths : Array<string> = ['/data/storage/el2/base/a.abc']; 4727 4728try { 4729 bundleManager.verifyAbc(abcPaths, true).then((data) => { 4730 hilog.info(0x0000, 'testTag', 'verifyAbc successfully'); 4731 }).catch((err: BusinessError) => { 4732 hilog.error(0x0000, 'testTag', 'verifyAbc failed. Cause: %{public}s', err.message); 4733 }); 4734} catch (err) { 4735 let message = (err as BusinessError).message; 4736 hilog.error(0x0000, 'testTag', 'verifyAbc failed. Cause: %{public}s', message); 4737} 4738``` 4739 4740### bundleManager.deleteAbc<sup>11+</sup> 4741 4742deleteAbc(abcPath: string): Promise\<void> 4743 4744Deletes an .abc file based on the specified file path. This API uses a promise to return the result. 4745 4746**Required permissions**: ohos.permission.RUN_DYN_CODE 4747 4748**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4749 4750**Parameters** 4751 4752| Name | Type | Mandatory| Description | 4753| ----------- | ------ | ---- | ---------------------------- | 4754| abcPath | string | Yes | Path of the .abc file.| 4755 4756**Return value** 4757 4758| Type | Description | 4759| ----------------------------------------------------------- | --------------------------- | 4760| Promise\<void> | Promise that returns no value.| 4761 4762**Error codes** 4763 4764For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4765 4766| ID| Error Message | 4767| -------- | --------------------------------------| 4768| 17700202 | deleteAbc failed. | 4769 4770**Example** 4771 4772```ts 4773import bundleManager from '@ohos.bundle.bundleManager'; 4774import { BusinessError } from '@ohos.base'; 4775import hilog from '@ohos.hilog'; 4776let abcPath : string = '/data/storage/el2/base/a.abc'; 4777 4778try { 4779 bundleManager.deleteAbc(abcPath).then((data) => { 4780 hilog.info(0x0000, 'testTag', 'deleteAbc successfully'); 4781 }).catch((err: BusinessError) => { 4782 hilog.error(0x0000, 'testTag', 'deleteAbc failed. Cause: %{public}s', err.message); 4783 }); 4784} catch (err) { 4785 let message = (err as BusinessError).message; 4786 hilog.error(0x0000, 'testTag', 'deleteAbc failed. Cause: %{public}s', message); 4787} 4788``` 4789 4790### bundleManager.queryExtensionAbilityInfoSync<sup>11+</sup> 4791 4792queryExtensionAbilityInfoSync(extensionAbilityType: string, extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> 4793 4794Obtains the ExtensionAbility information based on the given ExtensionAbility type, ExtensionAbility flags, and user ID. 4795 4796**System API**: This is a system API. 4797 4798**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO 4799 4800**System capability**: SystemCapability.BundleManager.BundleFramework.Core 4801 4802**Parameters** 4803 4804| Name | Type | Mandatory| Description | 4805| --------------------- | ------------------------------- | ---- | --------------------------------------------------------- | 4806| extensionAbilityType | string | Yes | Type of the custom ExtensionAbility. | 4807| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Information flags to be contained in the returned **ExtensionAbilityInfo** object.| 4808| 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.| 4809 4810**Return value** 4811 4812| Type | Description | 4813| ------------------------------------------------------------ | -------------------------------------- | 4814| Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | An array of **ExtensionAbilityInfo** objects.| 4815 4816**Error codes** 4817 4818For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md). 4819 4820| ID| Error Message | 4821| -------- | -------------------------------------------- | 4822| 17700003 | The specified extensionAbility is not found. | 4823| 17700004 | The specified userId is invalid. | 4824 4825**Example** 4826 4827```ts 4828// Call the API with the userId parameter specified. 4829import bundleManager from '@ohos.bundle.bundleManager'; 4830import hilog from '@ohos.hilog'; 4831import { BusinessError } from '@ohos.base'; 4832 4833let extensionAbilityType = "form"; 4834let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4835let userId = 100; 4836 4837try { 4838 let data = bundleManager.queryExtensionAbilityInfoSync(extensionAbilityType, extensionFlags, userId) 4839 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4840} catch (err) { 4841 let message = (err as BusinessError).message; 4842 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4843} 4844``` 4845 4846```ts 4847// Call the API without passing in the userId parameter. 4848import bundleManager from '@ohos.bundle.bundleManager'; 4849import hilog from '@ohos.hilog'; 4850import { BusinessError } from '@ohos.base'; 4851 4852let extensionAbilityType = "form"; 4853let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; 4854 4855try { 4856 let data = bundleManager.queryExtensionAbilityInfoSync(extensionAbilityType, extensionFlags); 4857 hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfoSync successfully. Data: %{public}s', JSON.stringify(data)); 4858} catch (err) { 4859 let message = (err as BusinessError).message; 4860 hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfoSync failed: %{public}s', message); 4861} 4862``` 4863