1# @ohos.bundle.bundleManager (bundleManager)
2
3The bundleManager module provides APIs for obtaining application information, including [BundleInfo](js-apis-bundleManager-bundleInfo.md), [ApplicationInfo](js-apis-bundleManager-applicationInfo.md), [AbilityInfo](js-apis-bundleManager-abilityInfo.md), and [ExtensionAbility](js-apis-bundleManager-extensionAbilityInfo.md).
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 '@kit.AbilityKit';
13```
14
15## Enums
16
17### BundleFlag
18
19Enumerates the bundle flags, which indicate the type of bundle information to obtain.
20
21 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
22
23| Name                                         | Value        | Description                                                        |
24| --------------------------------------------- | ---------- | ------------------------------------------------------------ |
25| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
26| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
27| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
28| 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**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
29| 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**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
30| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
31| 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**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
32| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
33| 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.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
34| 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**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
35| GET_BUNDLE_INFO_WITH_ROUTER_MAP<sup>12+</sup> | 0x00000200 | Used to obtain the bundle information with the router map. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
36| GET_BUNDLE_INFO_WITH_SKILL<sup>12+</sup>      | 0x00000800 | Used to obtain the bundle information with the skills. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**, **GET_BUNDLE_INFO_WITH_ABILITY**, and **GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
37
38### ExtensionAbilityType
39
40Enumerates the types of ExtensionAbilities.
41
42 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
43
44| Name| Value| Description|
45|:----------------:|:---:|-----|
46| FORM             | 0   | [FormExtensionAbility](../apis-form-kit/js-apis-app-form-formExtensionAbility.md): provides APIs for widget development.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
47| WORK_SCHEDULER   | 1   | [WorkSchedulerExtensionAbility](../apis-backgroundtasks-kit/js-apis-WorkSchedulerExtensionAbility.md): enables applications to execute non-real-time tasks when the system is idle.|
48| INPUT_METHOD     | 2   | [InputMethodExtensionAbility](../apis-ime-kit/js-apis-inputmethod-extension-ability.md): provides APIs for developing input method applications.|
49| SERVICE          | 3   | <!--Del-->[<!--DelEnd-->ServiceExtensionAbility<!--Del-->](js-apis-app-ability-serviceExtensionAbility-sys.md)<!--DelEnd-->: enables applications to run in the background and provide services.|
50| ACCESSIBILITY    | 4   | <!--RP1-->[AccessibilityExtensionAbility](../apis-accessibility-kit/js-apis-application-accessibilityExtensionAbility.md)<!--RP1End-->: provides accessibility for access to and operations on the UI.|
51| DATA_SHARE       | 5   | <!--Del-->[<!--DelEnd-->DataShareExtensionAbility <!--Del-->](../apis-arkdata/js-apis-application-dataShareExtensionAbility-sys.md)<!--DelEnd-->: enables applications to read and write data.|
52| FILE_SHARE       | 6   | FileShareExtensionAbility: enables file sharing between applications. This ability is reserved and supported only by system applications.|
53| STATIC_SUBSCRIBER| 7   | <!--Del-->[<!--DelEnd-->StaticSubscriberExtensionAbility <!--Del-->](../apis-basic-services-kit/js-apis-application-staticSubscriberExtensionAbility-sys.md)<!--DelEnd-->: provides APIs for processing static events, such as the startup event.|
54| WALLPAPER        | 8   | WallpaperExtensionAbility: provides APIs to implement the home screen wallpaper. This ability is reserved and supported only by system applications.|
55| BACKUP           |  9  | [BackupExtensionAbility](../apis-core-file-kit/js-apis-application-backupExtensionAbility.md): provides APIs to implement application data backup and restore.|
56| WINDOW           |  10 | <!--Del-->[<!--DelEnd-->WindowExtensionAbility<!--Del-->](../apis-arkui/js-apis-application-windowExtensionAbility-sys.md)<!--DelEnd-->: allows system applications to display UIs of other applications.|
57| ENTERPRISE_ADMIN |  11 | [EnterpriseAdminExtensionAbility](../apis-mdm-kit/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.|
58| THUMBNAIL        | 13  | ThumbnailExtensionAbility: provides thumbnails for files. This ability is reserved and supported only by system applications.|
59| 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 and supported only by system applications.|
60| PRINT<sup>10+</sup> | 15 | PrintExtensionAbility: provides APIs for printing images. This ability is supported only by system applications.|
61| SHARE<sup>10+</sup> | 16 | [ShareExtensionAbility](js-apis-app-ability-shareExtensionAbility.md): provides sharing service templates based on UIExtensionAbilities.|
62| PUSH<sup>10+</sup> | 17 | PushExtensionAbility: provides APIs for pushing scenario-specific messages. This ability is reserved and supported only by system applications.|
63| DRIVER<sup>10+</sup> | 18 | [DriverExtensionAbility](../apis-driverdevelopment-kit/js-apis-app-ability-driverExtensionAbility.md): provides APIs for the peripheral driver. This ability is supported only by system applications.|
64| ACTION<sup>10+</sup> | 19 | [ActionExtensionAbility](js-apis-app-ability-actionExtensionAbility.md): provides custom action service templates based on UIExtensionAbilities.|
65| ADS_SERVICE<sup>11+</sup> | 20 | AdsServiceExtensionAbility: provides background customized ad services for external systems. This ability is supported only by system applications.|
66| EMBEDDED_UI<sup>12+</sup> | 21 | [EmbeddedUIExtensionAbility](js-apis-app-ability-embeddedUIExtensionAbility.md): provides ExtensionAbilities for the embeddable UI across process.|
67| INSIGHT_INTENT_UI<sup>12+</sup> | 22 | **InsightIntentUIExtensionAbility**: provides APIs that enable applications to be called by Celia intents so as to be displayed in windows.|
68| UNSPECIFIED      | 255 | No type is specified. It is used together with **queryExtensionAbilityInfo** to query all types of ExtensionAbilities.|
69
70
71### PermissionGrantState
72
73Enumerates the permission grant states.
74
75 **Atomic service API**: This API can be used in atomic services since API version 11.
76
77 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
78
79| Name| Value| Description|
80|:----------------:|:---:|:---:|
81| PERMISSION_DENIED|  -1 | Permission denied.|
82| PERMISSION_GRANTED |  0  |  Permission granted. |
83
84### SupportWindowMode
85
86Enumerates the window modes supported by the ability.
87
88 **Atomic service API**: This API can be used in atomic services since API version 11.
89
90 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
91
92| Name| Value| Description|
93|:----------------:|:---:|:---:|
94| FULL_SCREEN      | 0   | A window in full-screen mode is supported.|
95| SPLIT            | 1   | A window in split-screen mode is supported.|
96| FLOATING         | 2   | A floating window is supported.  |
97
98### LaunchType
99
100Enumerates the launch types of the ability.
101
102 **Atomic service API**: This API can be used in atomic services since API version 11.
103
104 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
105
106| Name| Value| Description|
107|:----------------:|:---:|:---:|
108| SINGLETON        | 0   | The ability can have only one instance.|
109| MULTITON         | 1   | The ability can have multiple instances.|
110| SPECIFIED        | 2   | The ability can have one or multiple instances, depending on the internal service of the ability.|
111
112### AbilityType
113
114Enumerates the types of abilities.
115
116 **Model restriction**: This API can be used only in the FA model.
117
118 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
119
120|  Name  | Value  |                            Description                           |
121| :-----: | ---- | :--------------------------------------------------------: |
122| PAGE    | 1    | Ability that has the UI. FA developed using the Page template to provide the capability of interacting with users.       |
123| SERVICE | 2    | Ability of the background service type, without the UI. PA developed using the Service template to provide the capability of running tasks in the background. |
124|  DATA   | 3    | PA developed using the Data template to provide unified data access for external systems.|
125
126### DisplayOrientation
127
128Enumerates the display orientations of the ability. This property applies only to the ability using the Page template.
129
130 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
131
132| Name                              |Value|Description|
133|:----------------------------------|---|---|
134| UNSPECIFIED                        |0 |Unspecified. The orientation is determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
135| LANDSCAPE                          |1 |Landscape.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
136| PORTRAIT                           |2 |Portrait.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
137| FOLLOW_RECENT                      |3 |The last display orientation is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
138| LANDSCAPE_INVERTED                 |4 |Reverse landscape.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
139| PORTRAIT_INVERTED                  |5 |Reverse portrait.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
140| AUTO_ROTATION                      |6 |Auto rotation.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
141| AUTO_ROTATION_LANDSCAPE            |7 |Auto rotation in the horizontal direction.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
142| AUTO_ROTATION_PORTRAIT             |8 |Auto rotation in the vertical direction.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
143| AUTO_ROTATION_RESTRICTED           |9 |Switched-determined auto rotation.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
144| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|Switched-determined auto rotation in the horizontal direction.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
145| AUTO_ROTATION_PORTRAIT_RESTRICTED  |11|Switched-determined auto rotation in the vertical direction.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
146| LOCKED                             |12|Locked.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
147| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup> |13|Auto rotation controlled by the switch and determined by the system.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
148| FOLLOW_DESKTOP<sup>12+</sup> |14|Following the orientation of the home screen.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
149
150### CompatiblePolicy<sup>10+</sup>
151
152Defines the version compatibility type of the shared library.
153
154 **Atomic service API**: This API can be used in atomic services since API version 11.
155
156 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
157
158| Name                  | Value  | Description                            |
159| ---------------------- | ---- | -------------------------------- |
160| BACKWARD_COMPATIBILITY | 1    | The shared library is backward compatible.|
161
162### ModuleType
163
164Enumerates the module types.
165
166 **Atomic service API**: This API can be used in atomic services since API version 11.
167
168 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
169
170| Name   | Value  | Description                |
171| ------- | ---- | -------------------- |
172| ENTRY   | 1    | Main module of the application.  |
173| FEATURE | 2    | Dynamic feature module of the application.|
174| SHARED  | 3    | Dynamic shared library module of the application. |
175
176### BundleType
177
178Enumerates the bundle types.
179
180 **Atomic service API**: This API can be used in atomic services since API version 11.
181
182 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
183
184| Name          | Value  | Description           |
185| -------------- | ---- | --------------- |
186| APP            | 0    | The bundle is an application.   |
187| ATOMIC_SERVICE | 1    | The bundle is an atomic service.|
188
189### MultiAppModeType<sup>12+</sup>
190Enumerates the types of the multi-app mode.
191
192 **System capability**: SystemCapability.BundleManager.BundleFramework.Core
193
194| Name| Value| Description|
195|:----------------:|:---:|:---:|
196| UNSPECIFIED|  0 | Unspecified type.|
197| MULTI_INSTANCE |  1  | Multiton mode. A resident process does not support this value. |
198| APP_CLONE |  2  |  App clone mode. |
199
200## APIs
201
202### bundleManager.getBundleInfoForSelf
203
204getBundleInfoForSelf(bundleFlags: number): Promise\<BundleInfo>
205
206Obtains the bundle information of this bundle based on the given bundle flags. This API uses a promise to return the result.
207
208**Atomic service API**: This API can be used in atomic services since API version 11.
209
210**System capability**: SystemCapability.BundleManager.BundleFramework.Core
211
212**Parameters**
213
214| Name    | Type  | Mandatory| Description               |
215| ----------- | ------ | ---- | --------------------- |
216| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
217
218**Return value**
219
220| Type                                                       | Description                                 |
221| ----------------------------------------------------------- | ------------------------------------- |
222| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information.|
223
224**Error codes**
225
226For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
227
228| ID| Error Message                                                    |
229| -------- | ------------------------------------------------------------ |
230| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
231
232**Example**
233
234```ts
235// Obtain application info with metadataArray.
236import { bundleManager } from '@kit.AbilityKit';
237import { BusinessError } from '@kit.BasicServicesKit';
238import { hilog } from '@kit.PerformanceAnalysisKit';
239
240let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
241
242try {
243  bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
244    hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
245  }).catch((err: BusinessError) => {
246    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
247  });
248} catch (err) {
249  let message = (err as BusinessError).message;
250  hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
251}
252```
253
254### bundleManager.getBundleInfoForSelf
255
256getBundleInfoForSelf(bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void
257
258Obtains the bundle information of this bundle based on the given bundle flags. This API uses an asynchronous callback to return the result.
259
260**Atomic service API**: This API can be used in atomic services since API version 11.
261
262**System capability**: SystemCapability.BundleManager.BundleFramework.Core
263
264**Parameters**
265
266| Name    | Type  | Mandatory| Description               |
267| ----------- | ------ | ---- | --------------------- |
268| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
269| 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.|
270
271**Error codes**
272
273For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
274
275| ID| Error Message                                                    |
276| -------- | ------------------------------------------------------------ |
277| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
278
279**Example**
280
281```ts
282// Obtain ability info with permissions.
283import { bundleManager } from '@kit.AbilityKit';
284import { BusinessError } from '@kit.BasicServicesKit';
285import { hilog } from '@kit.PerformanceAnalysisKit';
286
287let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
288
289try {
290  bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
291    if (err) {
292      hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
293    } else {
294      hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data));
295    }
296  });
297} catch (err) {
298  let message = (err as BusinessError).message;
299  hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
300}
301```
302
303### bundleManager.getProfileByAbility
304
305getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void
306
307Obtains the JSON string array of the current application's configuration file in the [metadata](../../quick-start/module-configuration-file.md#metadata) based on a given module name, ability name, and metadata name. This API uses an asynchronous callback to return the result.
308
309> **NOTE**
310>
311> 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.
312
313**Atomic service API**: This API can be used in atomic services since API version 11.
314
315**System capability**: SystemCapability.BundleManager.BundleFramework.Core
316
317**Parameters**
318
319| Name      | Type                         | Mandatory| Description                                                        |
320| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
321| moduleName   | string                        | Yes  | Module name.                                    |
322| abilityName  | string                        | Yes  | Name of the UIAbility component.                                   |
323| metadataName | string                        | Yes  | Metadata name of the UIAbility component, that is, **name** of the **metadata** tag under **abilities** in the **module.json5** file.                                 |
324| 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.|
325
326**Error codes**
327
328For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
329
330| ID| Error Message                                                    |
331| -------- | ------------------------------------------------------------ |
332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
333| 17700002 | The specified moduleName is not existed.                      |
334| 17700003 | The specified abilityName is not existed.                     |
335| 17700024 | Failed to get the profile because there is no profile in the HAP. |
336| 17700026 | The specified bundle is disabled.                             |
337| 17700029 | The specified ability is disabled.                            |
338
339**Example**
340
341```ts
342import { bundleManager } from '@kit.AbilityKit';
343import { BusinessError } from '@kit.BasicServicesKit';
344import { hilog } from '@kit.PerformanceAnalysisKit';
345
346let moduleName = 'entry';
347let abilityName = 'EntryAbility';
348let metadataName = 'ability_metadata';
349
350try {
351  bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
352    if (err) {
353      hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
354    } else {
355      hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data));
356    }
357  });
358} catch (err) {
359  let message = (err as BusinessError).message;
360  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
361}
362```
363
364### bundleManager.getProfileByAbility
365
366getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string\>\>
367
368Obtains the JSON string array of the current application's configuration file in the [metadata](../../quick-start/module-configuration-file.md#metadata) based on a given module name, ability name, and metadata name. This API uses a promise to return the result.
369
370> **NOTE**
371>
372> 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.
373
374**Atomic service API**: This API can be used in atomic services since API version 11.
375
376**System capability**: SystemCapability.BundleManager.BundleFramework.Core
377
378**Parameters**
379
380| Name      | Type  | Mandatory| Description                      |
381| ------------ | ------ | ---- | -------------------------- |
382| moduleName   | string | Yes  | Module name.  |
383| abilityName  | string | Yes  | Name of the UIAbility component. |
384| metadataName | string | No  | Metadata name of the UIAbility component, that is, **name** of the **metadata** tag under **abilities** in the **module.json5** file. The default value is null.|
385
386**Return value**
387
388| Type                   | Description                           |
389| ----------------------- | ------------------------------- |
390| Promise<Array\<string>> | Promise used to return the array of JSON strings obtained.|
391
392**Error codes**
393
394For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
395
396| ID| Error Message                                                    |
397| -------- | ------------------------------------------------------------ |
398| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
399| 17700002 | The specified moduleName is not existed.                      |
400| 17700003 | The specified abilityName is not existed.                     |
401| 17700024 | Failed to get the profile because there is no profile in the HAP. |
402| 17700026 | The specified bundle is disabled.                             |
403| 17700029 | The specified ability is disabled.                            |
404
405**Example**
406
407```ts
408import { bundleManager } from '@kit.AbilityKit';
409import { BusinessError } from '@kit.BasicServicesKit';
410import { hilog } from '@kit.PerformanceAnalysisKit';
411
412let moduleName = 'entry';
413let abilityName = 'EntryAbility';
414
415try {
416  bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
417    hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
418  }).catch((err: BusinessError) => {
419    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
420  });
421} catch (err) {
422  let message = (err as BusinessError).message;
423  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
424}
425```
426
427```ts
428import { bundleManager } from '@kit.AbilityKit';
429import { BusinessError } from '@kit.BasicServicesKit';
430import { hilog } from '@kit.PerformanceAnalysisKit';
431
432let moduleName = 'entry';
433let abilityName = 'EntryAbility';
434let metadataName = 'ability_metadata';
435
436try {
437  bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
438    hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
439  }).catch((err: BusinessError) => {
440    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
441  });
442} catch (err) {
443  let message = (err as BusinessError).message;
444  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
445}
446```
447
448### bundleManager.getProfileByAbilitySync<sup>10+</sup>
449
450getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array\<string\>
451
452Obtains the JSON string array of the current application's configuration file in the [metadata](../../quick-start/module-configuration-file.md#metadata) based on a given module name, ability name, and metadata name. This API returns the result synchronously. The result value is a string array.
453
454> **NOTE**
455>
456> 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.
457
458**Atomic service API**: This API can be used in atomic services since API version 11.
459
460**System capability**: SystemCapability.BundleManager.BundleFramework.Core
461
462**Parameters**
463
464| Name      | Type  | Mandatory| Description                      |
465| ------------ | ------ | ---- | -------------------------- |
466| moduleName   | string | Yes  | Module name.  |
467| abilityName  | string | Yes  | Name of the UIAbility component. |
468| metadataName | string | No  | Metadata name of the UIAbility component, that is, **name** of the **metadata** tag under **abilities** in the **module.json5** file. The default value is null.|
469
470**Return value**
471
472| Type                   | Description                           |
473| ----------------------- | ------------------------------- |
474| Array\<string> | An array of JSON strings.|
475
476**Error codes**
477
478For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
479
480| ID| Error Message                                                    |
481| -------- | ------------------------------------------------------------ |
482| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
483| 17700002 | The specified moduleName is not existed.                      |
484| 17700003 | The specified abilityName is not existed.                     |
485| 17700024 | Failed to get the profile because there is no profile in the HAP. |
486| 17700026 | The specified bundle is disabled.                             |
487| 17700029 | The specified ability is disabled.                            |
488
489**Example**
490
491```ts
492import { bundleManager } from '@kit.AbilityKit';
493import { BusinessError } from '@kit.BasicServicesKit';
494import { hilog } from '@kit.PerformanceAnalysisKit';
495
496let moduleName = 'entry';
497let abilityName = 'EntryAbility';
498
499try {
500  let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName);
501  hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
502} catch (err) {
503  let message = (err as BusinessError).message;
504  hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message);
505}
506```
507
508```ts
509import { bundleManager } from '@kit.AbilityKit';
510import { BusinessError } from '@kit.BasicServicesKit';
511import { hilog } from '@kit.PerformanceAnalysisKit';
512
513let moduleName: string = 'entry';
514let abilityName: string = 'EntryAbility';
515let metadataName: string = 'ability_metadata';
516
517try {
518  let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName, metadataName);
519  hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
520} catch (err) {
521  let message = (err as BusinessError).message;
522  hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message);
523}
524```
525
526### bundleManager.getProfileByExtensionAbility
527
528getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void
529
530Obtains the JSON string array of the current application's configuration file in the [metadata](../../quick-start/module-configuration-file.md#metadata) based on a given module name, ExtensionAbility name, and metadata name. This API uses an asynchronous callback to return the result.
531
532> **NOTE**
533>
534> 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.
535
536**Atomic service API**: This API can be used in atomic services since API version 11.
537
538**System capability**: SystemCapability.BundleManager.BundleFramework.Core
539
540**Parameters**
541
542| Name                | Type                         | Mandatory| Description                                                        |
543| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ |
544| moduleName           | string                        | Yes  | Module name.                                  |
545| extensionAbilityName | string                        | Yes  | Name of the ExtensionAbility component.                        |
546| metadataName         | string                        | Yes  |  Metadata name of the ExtensionAbility component, that is, **name** of the **metadata** tag under **extensionAbilities** in the **module.json5** file.                                |
547| 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.|
548
549**Error codes**
550
551For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
552
553| ID| Error Message                                                    |
554| -------- | ------------------------------------------------------------ |
555| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
556| 17700002 | The specified moduleName is not existed.                      |
557| 17700003 | The specified extensionAbilityName not existed.            |
558| 17700024 | Failed to get the profile because there is no profile in the HAP. |
559| 17700026 | The specified bundle is disabled.                             |
560
561**Example**
562
563```ts
564import { bundleManager } from '@kit.AbilityKit';
565import { BusinessError } from '@kit.BasicServicesKit';
566import { hilog } from '@kit.PerformanceAnalysisKit';
567
568let moduleName = 'entry';
569let extensionAbilityName = 'com.example.myapplication.extension';
570let metadataName = 'ability_metadata';
571
572try {
573  bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => {
574    if (err) {
575      hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
576    } else {
577      hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data));
578    }
579  });
580} catch (err) {
581  let message = (err as BusinessError).message;
582  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', message);
583}
584```
585
586### bundleManager.getProfileByExtensionAbility
587
588getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string\>\>
589
590Obtains the JSON string array of the current application's configuration file in the [metadata](../../quick-start/module-configuration-file.md#metadata) based on a given module name, ExtensionAbility name, and metadata name. This API uses a promise to return the result.
591
592> **NOTE**
593>
594> 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.
595
596**Atomic service API**: This API can be used in atomic services since API version 11.
597
598**System capability**: SystemCapability.BundleManager.BundleFramework.Core
599
600**Parameters**
601
602| Name                | Type  | Mandatory| Description                              |
603| -------------------- | ------ | ---- | ---------------------------------- |
604| moduleName           | string | Yes  | Module name.          |
605| extensionAbilityName | string | Yes  | Name of the ExtensionAbility component.|
606| metadataName         | string | No  |  Metadata name of the ExtensionAbility component, that is, **name** of the **metadata** tag under **extensionAbilities** in the **module.json5** file. The default value is null.        |
607
608**Return value**
609
610| Type                   | Description                               |
611| ----------------------- | ----------------------------------- |
612| Promise<Array\<string>> | Promise used to return the array of JSON strings obtained.|
613
614**Error codes**
615
616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
617
618| ID| Error Message                                                    |
619| -------- | ------------------------------------------------------------ |
620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
621| 17700002 | The specified moduleName is not existed.                      |
622| 17700003 | The specified extensionAbilityName not existed.            |
623| 17700024 | Failed to get the profile because there is no profile in the HAP. |
624| 17700026 | The specified bundle is disabled.                             |
625
626**Example**
627
628```ts
629import { bundleManager } from '@kit.AbilityKit';
630import { BusinessError } from '@kit.BasicServicesKit';
631import { hilog } from '@kit.PerformanceAnalysisKit';
632
633let moduleName = 'entry';
634let extensionAbilityName = 'com.example.myapplication.extension';
635let metadataName = 'ability_metadata';
636
637try {
638  bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
639    hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
640  }).catch((err: BusinessError) => {
641    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
642  });
643} catch (err) {
644  let message = (err as BusinessError).message;
645  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message);
646}
647
648try {
649  bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => {
650    hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
651  }).catch((err: BusinessError) => {
652    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
653  });
654} catch (err) {
655  let message = (err as BusinessError).message;
656  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message);
657}
658```
659
660### bundleManager.getProfileByExtensionAbilitySync<sup>10+</sup>
661
662getProfileByExtensionAbilitySync(moduleName: string, extensionAbilityName: string, metadataName?: string): Array\<string\>
663
664Obtains the JSON string array of the current application's configuration file in the [metadata](../../quick-start/module-configuration-file.md#metadata) based on a given module name, ExtensionAbility name, and metadata name. This API returns the result synchronously. The result value is a string array.
665
666> **NOTE**
667>
668> 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.
669
670**Atomic service API**: This API can be used in atomic services since API version 11.
671
672**System capability**: SystemCapability.BundleManager.BundleFramework.Core
673
674**Parameters**
675
676| Name                | Type  | Mandatory| Description                              |
677| -------------------- | ------ | ---- | ---------------------------------- |
678| moduleName           | string | Yes  | Module name.          |
679| extensionAbilityName | string | Yes  | Name of the ExtensionAbility component.|
680| metadataName         | string | No  |  Metadata name of the ExtensionAbility component, that is, **name** of the **metadata** tag under **extensionAbilities** in the **module.json5** file. The default value is null.        |
681
682**Return value**
683
684| Type                   | Description                               |
685| ----------------------- | ----------------------------------- |
686| Array\<string> | An array of JSON strings.|
687
688**Error codes**
689
690For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
691
692| ID| Error Message                                                    |
693| -------- | ------------------------------------------------------------ |
694| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
695| 17700002 | The specified moduleName is not existed.                      |
696| 17700003 | The specified extensionAbilityName not existed.            |
697| 17700024 | Failed to get the profile because there is no profile in the HAP. |
698| 17700026 | The specified bundle is disabled.                             |
699
700**Example**
701
702```ts
703import { bundleManager } from '@kit.AbilityKit';
704import { BusinessError } from '@kit.BasicServicesKit';
705import { hilog } from '@kit.PerformanceAnalysisKit';
706
707let moduleName = 'entry';
708let extensionAbilityName = 'com.example.myapplication.extension';
709let metadataName = 'ability_metadata';
710
711try {
712  let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName);
713  hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
714} catch (err) {
715  let message = (err as BusinessError).message;
716  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message);
717}
718
719try {
720  let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName, metadataName);
721  hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
722} catch (err) {
723  let message = (err as BusinessError).message;
724  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message);
725}
726```
727
728### bundleManager.getBundleInfoForSelfSync<sup>10+</sup>
729
730getBundleInfoForSelfSync(bundleFlags: number): BundleInfo
731
732Obtains the bundle information of this bundle based on the given bundle flags. This API returns the result synchronously.
733
734**Atomic service API**: This API can be used in atomic services since API version 11.
735
736**System capability**: SystemCapability.BundleManager.BundleFramework.Core
737
738**Parameters**
739
740| Name    | Type  | Mandatory| Description               |
741| ----------- | ------ | ---- | --------------------- |
742| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
743
744**Return value**
745
746| Type                                             | Description                |
747| ------------------------------------------------- | -------------------- |
748| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.|
749
750**Error codes**
751
752For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
753
754| ID| Error Message                                                    |
755| -------- | ------------------------------------------------------------ |
756| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
757
758**Example**
759
760```ts
761import { bundleManager } from '@kit.AbilityKit';
762import { BusinessError } from '@kit.BasicServicesKit';
763import { hilog } from '@kit.PerformanceAnalysisKit';
764
765let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
766
767try {
768  let data = bundleManager.getBundleInfoForSelfSync(bundleFlags);
769  hilog.info(0x0000, 'testTag', 'getBundleInfoForSelfSync successfully: %{public}s', JSON.stringify(data));
770} catch (err) {
771  let message = (err as BusinessError).message;
772  hilog.error(0x0000, 'testTag', 'getBundleInfoForSelfSync failed: %{public}s', message);
773}
774```
775
776### bundleManager.canOpenLink<sup>12+</sup>
777
778canOpenLink(link: string): boolean
779
780Checks whether a link can be opened. The scheme of the specified link must be configured in the **querySchemes** field of the **module.json** file.
781
782**Atomic service API**: This API can be used in atomic services since API version 12.
783
784**System capability**: SystemCapability.BundleManager.BundleFramework.Core
785
786**Parameters**
787
788| Name    | Type  | Mandatory| Description               |
789| ----------- | ------ | ---- | --------------------- |
790| link | string | Yes  | Link to check.|
791
792**Return value**
793
794| Type                                             | Description                |
795| ------------------------------------------------- | -------------------- |
796| boolean | **true**: The link can be opened.<br>**false**: The link cannot be opened.|
797
798**Error codes**
799
800For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
801
802| ID| Error Message                                                    |
803| -------- | ------------------------------------------------------------ |
804| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
805| 17700055 | The specified link is invalid.                      |
806| 17700056 | The scheme of the specified link is not in the querySchemes.        |
807
808**Example**
809
810```ts
811import { bundleManager } from '@kit.AbilityKit';
812import { BusinessError } from '@kit.BasicServicesKit';
813import { hilog } from '@kit.PerformanceAnalysisKit';
814
815try {
816  let link = 'welink://';
817  let data = bundleManager.canOpenLink(link);
818  hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));
819} catch (err) {
820  let message = (err as BusinessError).message;
821  hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
822}
823```
824
825### bundleManager.getLaunchWant<sup>13+</sup>
826
827getLaunchWant(): Want
828
829Obtains the **Want** parameter used to start the application.
830
831**Atomic service API**: This API can be used in atomic services since API version 13.
832
833**System capability**: SystemCapability.BundleManager.BundleFramework.Core
834
835**Return value**
836
837| Type                               | Description                                       |
838| ----------------------------------- | ------------------------------------------- |
839| [Want](js-apis-app-ability-want.md) | Want object that contains the bundle name and ability name.|
840
841**Error codes**
842
843For details about the error codes, see [Bundle Error Codes](errorcode-bundle.md).
844
845| ID| Error Message                     |
846| -------- | ----------------------------- |
847| 17700072 | The launch want is not found. |
848
849**Example**
850
851```ts
852import { BusinessError } from '@kit.BasicServicesKit';
853import { bundleManager } from '@kit.AbilityKit';
854import { hilog } from '@kit.PerformanceAnalysisKit';
855
856try {
857  let want = bundleManager.getLaunchWant();
858  hilog.info(0x0000, 'testTag', 'getLaunchWant ability name: %{public}s', want.abilityName);
859  hilog.info(0x0000, 'testTag', 'getLaunchWant bundle name: %{public}s', want.bundleName);
860} catch (error) {
861  let message = (error as BusinessError).message;
862  hilog.error(0x0000, 'testTag', 'getLaunchWant failed: %{public}s', message);
863}
864```
865
866### bundleManager.getBundleInfo<sup>14+</sup>
867
868getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void
869
870Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses an asynchronous callback to return the result.
871
872No permission is required for obtaining the caller's own information.
873
874**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
875
876**System capability**: SystemCapability.BundleManager.BundleFramework.Core
877
878**Parameters**
879
880| Name | Type  | Mandatory| Description                      |
881| ----------- | ------ | ---- | ---------------------------- |
882| bundleName  | string | Yes  | Bundle name.|
883| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
884| userId      | number | Yes  | User ID. |
885| 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.|
886
887**Error codes**
888
889For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
890
891| ID| Error Message                             |
892| -------- | ------------------------------------- |
893| 201 | Permission denied. |
894| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
895| 17700001 | The specified bundleName is not found. |
896| 17700004 | The specified user ID is not found.     |
897| 17700026 | The specified bundle is disabled.      |
898
899**Example**
900
901```ts
902// Obtain the bundle information with the ability information.
903import { bundleManager } from '@kit.AbilityKit';
904import { BusinessError } from '@kit.BasicServicesKit';
905import { hilog } from '@kit.PerformanceAnalysisKit';
906let bundleName = 'com.example.myapplication';
907let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY;
908let userId = 100;
909
910try {
911    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
912        if (err) {
913            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
914        } else {
915            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
916        }
917    });
918} catch (err) {
919    let message = (err as BusinessError).message;
920    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message);
921}
922```
923
924```ts
925// Obtain the bundle information with the metadata in the application information.
926import { bundleManager } from '@kit.AbilityKit';
927import { BusinessError } from '@kit.BasicServicesKit';
928import { hilog } from '@kit.PerformanceAnalysisKit';
929let bundleName = 'com.example.myapplication';
930let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
931let userId = 100;
932
933try {
934    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
935        if (err) {
936            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
937        } else {
938            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
939        }
940    });
941} catch (err) {
942    let message = (err as BusinessError).message;
943    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message);
944}
945```
946
947### bundleManager.getBundleInfo<sup>14+</sup>
948
949getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void
950
951Obtains the bundle information based on the given bundle name and bundle flags. This API uses an asynchronous callback to return the result.
952
953No permission is required for obtaining the caller's own information.
954
955**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
956
957**System capability**: SystemCapability.BundleManager.BundleFramework.Core
958
959**Parameters**
960
961| Name    | Type  | Mandatory| Description                      |
962| ----------- | ------ | ---- | ---------------------------- |
963| bundleName  | string | Yes  | Bundle name.|
964| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
965| 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.|
966
967**Error codes**
968
969For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
970
971| ID| Error Message                             |
972| -------- | ------------------------------------- |
973| 201 | Permission denied. |
974| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
975| 17700001 | The specified bundleName is not found. |
976| 17700026 | The specified bundle is disabled.      |
977
978**Example**
979
980```ts
981// Obtain the bundle information with the ExtensionAbility information.
982import { bundleManager } from '@kit.AbilityKit';
983import { BusinessError } from '@kit.BasicServicesKit';
984import { hilog } from '@kit.PerformanceAnalysisKit';
985let bundleName = 'com.example.myapplication';
986let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY;
987
988try {
989    bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => {
990        if (err) {
991            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
992        } else {
993            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
994        }
995    });
996} catch (err) {
997    let message = (err as BusinessError).message;
998    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', message);
999}
1000```
1001
1002### bundleManager.getBundleInfo<sup>14+</sup>
1003
1004getBundleInfo(bundleName: string, bundleFlags: number, userId?: number): Promise\<BundleInfo>
1005
1006Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses a promise to return the result.
1007
1008No permission is required for obtaining the caller's own information.
1009
1010**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1011
1012**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1013
1014**Parameters**
1015
1016| Name    | Type  | Mandatory| Description                      |
1017| ----------- | ------ | ---- | ---------------------------- |
1018| bundleName  | string | Yes  | Bundle name.|
1019| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.      |
1020| 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. |
1021
1022**Return value**
1023
1024| Type                                                       | Description                       |
1025| ----------------------------------------------------------- | --------------------------- |
1026| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information obtained.|
1027
1028**Error codes**
1029
1030For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1031
1032| ID| Error Message                           |
1033| -------- | --------------------------------------|
1034| 201 | Permission denied. |
1035| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1036| 17700001 | The specified bundleName is not found. |
1037| 17700004 | The specified user ID is not found.     |
1038| 17700026 | The specified bundle is disabled.      |
1039
1040**Example**
1041
1042```ts
1043// Obtain the bundle information with the application and signature information.
1044import { bundleManager } from '@kit.AbilityKit';
1045import { BusinessError } from '@kit.BasicServicesKit';
1046import { hilog } from '@kit.PerformanceAnalysisKit';
1047let bundleName = 'com.example.myapplication';
1048let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
1049let userId = 100;
1050
1051try {
1052    bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => {
1053        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
1054    }).catch((err: BusinessError) => {
1055        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
1056    });
1057} catch (err) {
1058    let message = (err as BusinessError).message;
1059    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message);
1060}
1061```
1062
1063```ts
1064import { bundleManager } from '@kit.AbilityKit';
1065import { BusinessError } from '@kit.BasicServicesKit';
1066import { hilog } from '@kit.PerformanceAnalysisKit';
1067let bundleName = 'com.example.myapplication';
1068let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
1069
1070try {
1071    bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => {
1072        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
1073    }).catch((err: BusinessError) => {
1074        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
1075    });
1076} catch (err) {
1077    let message = (err as BusinessError).message;
1078    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', message);
1079}
1080
1081```
1082
1083### bundleManager.getBundleInfoSync<sup>14+</sup>
1084
1085getBundleInfoSync(bundleName: string, bundleFlags: number, userId: number): BundleInfo
1086
1087Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API returns the result synchronously.
1088
1089No permission is required for obtaining the caller's own information.
1090
1091**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1092
1093**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1094
1095**Parameters**
1096
1097| Name      | Type  | Mandatory| Description                                                    |
1098| ----------- | ------ | ---- | -------------------------------------------------------- |
1099| bundleName  | string | Yes  | Bundle name.                                |
1100| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
1101| userId      | number | Yes  | User ID.                                            |
1102
1103**Return value**
1104
1105| Type      | Description                |
1106| ---------- | -------------------- |
1107| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.|
1108
1109**Error codes**
1110
1111For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1112
1113| ID| Error Message                            |
1114| -------- | ------------------------------------- |
1115| 201 | Permission denied. |
1116| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1117| 17700001 | The specified bundleName is not found. |
1118| 17700004 | The specified user ID is not found.     |
1119| 17700026 | The specified bundle is disabled.      |
1120
1121**Example**
1122
1123```ts
1124import { bundleManager } from '@kit.AbilityKit';
1125import { BusinessError } from '@kit.BasicServicesKit';
1126import { hilog } from '@kit.PerformanceAnalysisKit';
1127let bundleName = 'com.example.myapplication';
1128let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
1129let userId = 100;
1130
1131try {
1132    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
1133    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
1134} catch (err) {
1135    let message = (err as BusinessError).message;
1136    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message);
1137}
1138```
1139
1140### bundleManager.getBundleInfoSync<sup>14+</sup>
1141
1142getBundleInfoSync(bundleName: string, bundleFlags: number): BundleInfo
1143
1144Obtains the bundle information based on the given bundle name and bundle flags. This API returns the result synchronously.
1145
1146No permission is required for obtaining the caller's own information.
1147
1148**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1149
1150**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1151
1152**Parameters**
1153
1154| Name     | Type                 | Mandatory| Description                                                  |
1155| ----------- | --------------------- | ---- | ------------------------------------------------------ |
1156| bundleName  | string                | Yes  | Bundle name.                            |
1157| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | Yes  | Type of the bundle information to obtain.|
1158
1159**Return value**
1160
1161| Type                                             | Description                |
1162| ------------------------------------------------- | -------------------- |
1163| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.|
1164
1165**Error codes**
1166
1167For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1168
1169| ID| Error Message                              |
1170| -------- | -------------------------------------- |
1171| 201 | Permission denied. |
1172| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1173| 17700001 | The specified bundleName is not found. |
1174| 17700026 | The specified bundle is disabled.      |
1175
1176**Example**
1177
1178```ts
1179import { bundleManager } from '@kit.AbilityKit';
1180import { BusinessError } from '@kit.BasicServicesKit';
1181import { hilog } from '@kit.PerformanceAnalysisKit';
1182let bundleName = 'com.example.myapplication';
1183let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
1184try {
1185    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags);
1186    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
1187} catch (err) {
1188    let message = (err as BusinessError).message;
1189    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', message);
1190}
1191```
1192
1193### bundleManager.getBundleNameByUid<sup>14+</sup>
1194
1195getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void
1196
1197Obtains the bundle name based on the given UID. This API uses an asynchronous callback to return the result.
1198
1199**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1200
1201**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1202
1203**Parameters**
1204
1205| Name  | Type                  | Mandatory| Description                                                        |
1206| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1207| uid      | number                 | Yes  | UID of the application.                                           |
1208| 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.|
1209
1210**Error codes**
1211
1212For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1213
1214| ID| Error Message           |
1215| -------- | --------------------- |
1216| 201 | Permission denied. |
1217| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1218| 17700021 | The uid is not found. |
1219
1220**Example**
1221
1222```ts
1223import { bundleManager } from '@kit.AbilityKit';
1224import { BusinessError } from '@kit.BasicServicesKit';
1225import { hilog } from '@kit.PerformanceAnalysisKit';
1226let uid = 20010005;
1227try {
1228    bundleManager.getBundleNameByUid(uid, (err, data) => {
1229        if (err) {
1230            hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message);
1231        } else {
1232            hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data));
1233        }
1234    });
1235} catch (err) {
1236    let message = (err as BusinessError).message;
1237    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', message);
1238}
1239```
1240
1241### bundleManager.getBundleNameByUid<sup>14+</sup>
1242
1243getBundleNameByUid(uid: number): Promise\<string>
1244
1245Obtains the bundle name based on the given UID. This API uses a promise to return the result.
1246
1247**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1248
1249**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1250
1251**Parameters**
1252
1253| Name| Type  | Mandatory| Description               |
1254| ---- | ------ | ---- | ------------------ |
1255| uid  | number | Yes  | UID of the application.|
1256
1257**Return value**
1258
1259| Type            | Description                       |
1260| ---------------- | --------------------------- |
1261| Promise\<string> | Promise used to return the bundle name obtained.|
1262
1263**Error codes**
1264
1265For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1266
1267| ID| Error Message           |
1268| -------- | ---------------------|
1269| 201 | Permission denied. |
1270| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1271| 17700021 | The uid is not found. |
1272
1273**Example**
1274
1275```ts
1276import { bundleManager } from '@kit.AbilityKit';
1277import { BusinessError } from '@kit.BasicServicesKit';
1278import { hilog } from '@kit.PerformanceAnalysisKit';
1279let uid = 20010005;
1280try {
1281    bundleManager.getBundleNameByUid(uid).then((data) => {
1282        hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data));
1283    }).catch((err: BusinessError) => {
1284        hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message);
1285    });
1286} catch (err) {
1287    let message = (err as BusinessError).message;
1288    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', message);
1289}
1290```
1291
1292### bundleManager.getBundleNameByUidSync<sup>14+</sup>
1293
1294getBundleNameByUidSync(uid: number): string
1295
1296Obtains the bundle name based on the given UID. This API returns the result synchronously.
1297
1298**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1299
1300**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1301
1302**Parameters**
1303
1304| Name| Type  | Mandatory| Description               |
1305| ---- | ------ | ---- | ------------------ |
1306| uid  | number | Yes  | UID of the application.|
1307
1308**Return value**
1309
1310| Type            | Description                       |
1311| ---------------- | --------------------------- |
1312| string | Bundle name obtained.|
1313
1314**Error codes**
1315
1316For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1317
1318| ID| Error Message           |
1319| -------- | ---------------------|
1320| 201 | Permission denied. |
1321| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1322| 17700021 | The uid is not found. |
1323
1324**Example**
1325
1326```ts
1327import { bundleManager } from '@kit.AbilityKit';
1328import { BusinessError } from '@kit.BasicServicesKit';
1329import { hilog } from '@kit.PerformanceAnalysisKit';
1330let uid = 20010005;
1331try {
1332    let data = bundleManager.getBundleNameByUidSync(uid);
1333    hilog.info(0x0000, 'testTag', 'getBundleNameByUidSync successfully. Data: %{public}s', JSON.stringify(data));
1334} catch (err) {
1335    let message = (err as BusinessError).message;
1336    hilog.error(0x0000, 'testTag', 'getBundleNameByUidSync failed. Cause: %{public}s', message);
1337}
1338```
1339
1340### bundleManager.getAppCloneIdentity<sup>14+</sup>
1341
1342getAppCloneIdentity(uid: number): Promise\<AppCloneIdentity>;
1343
1344Obtains the bundle name and app index of an application clone based on the given UID. This API uses a promise to return the result.
1345
1346**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
1347
1348**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1349
1350**Parameters**
1351
1352| Name    | Type  | Mandatory| Description                      |
1353| ---------- | ------ | ---- | ---------------------------|
1354|    uid     | number |  Yes |     UID of the application.     |
1355
1356**Return value**
1357
1358| Type                                                       | Description                       |
1359| ----------------------------------------------------------- | --------------------------- |
1360| Promise\<AppCloneIdentity> | Promise used to return \<AppCloneIdentity>.|
1361
1362**Error codes**
1363
1364For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1365
1366| ID| Error Message                           |
1367| -------- | --------------------------------------|
1368| 201 | Permission denied. |
1369| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1370| 17700021 | The uid is not found. |
1371
1372**Example**
1373
1374```ts
1375import { bundleManager } from '@kit.AbilityKit';
1376import { BusinessError } from '@kit.BasicServicesKit';
1377import { hilog } from '@kit.PerformanceAnalysisKit';
1378let uid = 20010005;
1379
1380try {
1381    bundleManager.getAppCloneIdentity(uid).then((res: bundleManager.AppCloneIdentity) => {
1382        hilog.info(0x0000, 'testTag', 'getAppCloneIdentity res = %{public}s', JSON.stringify(res));
1383    }).catch((err: BusinessError) => {
1384        hilog.error(0x0000, 'testTag', 'getAppCloneIdentity failed. Cause: %{public}s', err.message);
1385    });
1386} catch (err) {
1387    let message = (err as BusinessError).message;
1388    hilog.error(0x0000, 'testTag', 'getAppCloneIdentity failed. Cause: %{public}s', message);
1389}
1390```
1391