1# @ohos.bundle.bundleManager (bundleManager模块)
2
3本模块提供应用信息查询能力,支持[BundleInfo](js-apis-bundleManager-bundleInfo.md)、[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)、[AbilityInfo](js-apis-bundleManager-abilityInfo.md)、[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)等信息的查询。
4
5> **说明:**
6> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7
8## 导入模块
9
10```ts
11import { bundleManager } from '@kit.AbilityKit';
12```
13
14## 枚举
15
16### BundleFlag
17
18包信息标志,指示需要获取的包信息的内容。
19
20 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core21
22| 名称                                          | 值         | 说明                                                         |
23| --------------------------------------------- | ---------- | ------------------------------------------------------------ |
24| GET_BUNDLE_INFO_DEFAULT                       | 0x00000000 | 用于获取默认bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
25| GET_BUNDLE_INFO_WITH_APPLICATION              | 0x00000001 | 用于获取包含applicationInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、hapModuleInfo、ability、extensionAbility和permission的信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
26| GET_BUNDLE_INFO_WITH_HAP_MODULE               | 0x00000002 | 用于获取包含hapModuleInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability、extensionAbility和permission的信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
27| GET_BUNDLE_INFO_WITH_ABILITY                  | 0x00000004 | 用于获取包含ability的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、extensionAbility和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
28| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY        | 0x00000008 | 用于获取包含extensionAbility的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability 和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
29| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION     | 0x00000010 | 用于获取包含permission的bundleInfo。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、extensionAbility和ability的信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
30| GET_BUNDLE_INFO_WITH_METADATA                 | 0x00000020 | 用于获取applicationInfo、moduleInfo和abilityInfo中包含的metadata。它不能单独使用,它需要与GET_BUNDLE_INFO_WITH_APPLICATION、GET_BUNDLE_INFO_WITH_HAP_MODULE、GET_BUNDLE_INFO_WITH_ABILITY、GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY一起使用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
31| GET_BUNDLE_INFO_WITH_DISABLE                  | 0x00000040 | 用于获取application被禁用的BundleInfo和被禁用的Ability信息。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
32| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO           | 0x00000080 | 用于获取包含signatureInfo的bundleInfo。获取的bundleInfo不包含applicationInfo、hapModuleInfo、extensionAbility、ability和permission的信息。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
33| GET_BUNDLE_INFO_WITH_MENU<sup>11+</sup>       | 0x00000100 | 用于获取包含fileContextMenuConfig的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
34| GET_BUNDLE_INFO_WITH_ROUTER_MAP<sup>12+</sup> | 0x00000200 | 用于获取包含routerMap的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
35| GET_BUNDLE_INFO_WITH_SKILL<sup>12+</sup>      | 0x00000800 | 用于获取包含skills的bundleInfo。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE、GET_BUNDLE_INFO_WITH_ABILITY、GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY一起使用。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
36
37### ExtensionAbilityType
38
39指示扩展组件的类型。
40
41 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core42
43| 名称 | 值 | 说明 |
44|:----------------:|:---:|-----|
45| FORM             | 0   | [FormExtensionAbility](../apis-form-kit/js-apis-app-form-formExtensionAbility.md):卡片扩展能力,提供卡片开发能力。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
46| WORK_SCHEDULER   | 1   | [WorkSchedulerExtensionAbility](../apis-backgroundtasks-kit/js-apis-WorkSchedulerExtensionAbility.md):延时任务扩展能力,允许应用在系统闲时执行实时性不高的任务。 |
47| INPUT_METHOD     | 2   | [InputMethodExtensionAbility](../apis-ime-kit/js-apis-inputmethod-extension-ability.md):输入法扩展能力,用于开发输入法应用。 |
48| SERVICE          | 3   | <!--Del-->[<!--DelEnd-->ServiceExtensionAbility<!--Del-->](js-apis-app-ability-serviceExtensionAbility-sys.md)<!--DelEnd-->:后台服务扩展能力,提供后台运行并对外提供相应能力。 |
49| ACCESSIBILITY    | 4   | <!--RP1-->[AccessibilityExtensionAbility](../apis-accessibility-kit/js-apis-inner-application-accessibilityExtensionContext.md)<!--RP1End-->:无障碍服务扩展能力,支持访问与操作前台界面。 |
50| DATA_SHARE       | 5   | <!--Del-->[<!--DelEnd-->DataShareExtensionAbility <!--Del-->](../apis-arkdata/js-apis-application-dataShareExtensionAbility-sys.md)<!--DelEnd-->:数据共享扩展能力,用于对外提供数据读写服务。 |
51| FILE_SHARE       | 6   | FileShareExtensionAbility:文件共享扩展能力,用于应用间的文件分享。预留能力,仅系统应用支持。 |
52| STATIC_SUBSCRIBER| 7   | <!--Del-->[<!--DelEnd-->StaticSubscriberExtensionAbility <!--Del-->](../apis-basic-services-kit/js-apis-application-staticSubscriberExtensionAbility-sys.md)<!--DelEnd-->:静态广播扩展能力,用于处理静态事件,比如开机事件。 |
53| WALLPAPER        | 8   | WallpaperExtensionAbility:壁纸扩展能力,用于实现桌面壁纸。预留能力,仅系统应用支持。 |
54| BACKUP           |  9  | [BackupExtensionAbility](../apis-core-file-kit/js-apis-application-backupExtensionAbility.md):数据备份扩展能力,提供应用数据的备份恢复能力。 |
55| WINDOW           |  10 | <!--Del-->[<!--DelEnd-->WindowExtensionAbility<!--Del-->](../apis-arkui/js-apis-application-windowExtensionAbility-sys.md)<!--DelEnd-->:界面组合扩展能力,允许系统应用进行跨应用的界面拉起和嵌入。 |
56| ENTERPRISE_ADMIN |  11 | [EnterpriseAdminExtensionAbility](../apis-mdm-kit/js-apis-EnterpriseAdminExtensionAbility.md):企业设备管理扩展能力,提供企业管理时处理管理事件的能力,比如设备上应用安装事件、锁屏密码输入错误次数过多事件等。 |
57| THUMBNAIL        | 13  | ThumbnailExtensionAbility:文件缩略图扩展能力,用于为文件提供图标缩略图的能力。预留能力,仅系统应用支持。 |
58| PREVIEW          | 14  | PreviewExtensionAbility:文件预览扩展能力,提供文件预览的能力,其他应用可以直接在应用中嵌入显示。预留能力,仅系统应用支持。 |
59| PRINT<sup>10+</sup> | 15 | PrintExtensionAbility:文件打印扩展能力,提供应用打印照片、文档等办公场景。仅系统应用支持。 |
60| SHARE<sup>10+</sup> | 16 | [ShareExtensionAbility](js-apis-app-ability-shareExtensionAbility.md):提供分享业务能力,为开发者提供基于UIExtension的分享业务模板。 |
61| PUSH<sup>10+</sup> | 17 | PushExtensionAbility:推送扩展能力,提供推送场景化消息能力。预留能力,仅系统应用支持。 |
62| DRIVER<sup>10+</sup> | 18 | [DriverExtensionAbility](../apis-driverdevelopment-kit/js-apis-app-ability-driverExtensionAbility.md):驱动扩展能力,提供外设驱动扩展能力,仅系统应用支持。 |
63| ACTION<sup>10+</sup> | 19 | [ActionExtensionAbility](js-apis-app-ability-actionExtensionAbility.md):自定义服务扩展能力,为开发者提供基于UIExtension的自定义操作业务模板。 |
64| ADS_SERVICE<sup>11+</sup> | 20 | AdsServiceExtensionAbility:广告服务扩展能力,对外提供后台自定义广告业务服务,仅系统应用支持。 |
65| EMBEDDED_UI<sup>12+</sup> | 21 | [EmbeddedUIExtensionAbility](js-apis-app-ability-embeddedUIExtensionAbility.md):嵌入式UI扩展能力,提供跨进程界面嵌入的能力。 |
66| INSIGHT_INTENT_UI<sup>12+</sup> | 22 | InsightIntentUIExtensionAbility:为开发者提供能被小艺意图调用,以窗口形态呈现内容的扩展能力。 |
67| UNSPECIFIED      | 255 | 不指定类型,配合queryExtensionAbilityInfo接口可以查询所有类型的ExtensionAbility。 |
68
69
70### PermissionGrantState
71
72指示权限授予状态。
73
74 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
75
76 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core77
78| 名称 | 值 | 说明 |
79|:----------------:|:---:|:---:|
80| PERMISSION_DENIED|  -1 | 拒绝授予权限。 |
81| PERMISSION_GRANTED |  0  |  授予权限。  |
82
83### SupportWindowMode
84
85标识该组件所支持的窗口模式。
86
87 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
88
89 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core90
91| 名称 | 值 | 说明 |
92|:----------------:|:---:|:---:|
93| FULL_SCREEN      | 0   | 窗口支持全屏显示。 |
94| SPLIT            | 1   | 窗口支持分屏显示。 |
95| FLOATING         | 2   | 支持窗口化显示。   |
96
97### LaunchType
98
99指示组件的启动方式。
100
101 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
102
103 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core104
105| 名称 | 值 | 说明 |
106|:----------------:|:---:|:---:|
107| SINGLETON        | 0   | ability的启动模式,表示单实例。 |
108| MULTITON         | 1   | ability的启动模式,表示普通多实例。 |
109| SPECIFIED        | 2   | ability的启动模式,表示该ability内部根据业务自己指定多实例。 |
110
111### AbilityType
112
113指示Ability组件的类型。
114
115 **模型约束:** 仅可在FA模型下使用
116
117 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core118
119|  名称   | 值   |                            说明                            |
120| :-----: | ---- | :--------------------------------------------------------: |
121| PAGE    | 1    | UI界面类型的Ability。表示基于Page模板开发的FA,用于提供与用户交互的能力。        |
122| SERVICE | 2    | 后台服务类型的Ability,无UI界面。表示基于Service模板开发的PA,用于提供后台运行任务的能力。  |
123|  DATA   | 3    | 表示基于Data模板开发的PA,用于对外部提供统一的数据访问对象。 |
124
125### DisplayOrientation
126
127标识该Ability的显示模式。该标签仅适用于page类型的Ability。
128
129 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core130
131| 名称                               |值 |说明 |
132|:----------------------------------|---|---|
133| UNSPECIFIED                        |0 |表示未定义方向模式,由系统判定。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
134| LANDSCAPE                          |1 |表示横屏显示模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
135| PORTRAIT                           |2 |表示竖屏显示模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
136| FOLLOW_RECENT                      |3 |表示跟随上一个显示模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
137| LANDSCAPE_INVERTED                 |4 |表示反向横屏显示模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
138| PORTRAIT_INVERTED                  |5 |表示反向竖屏显示模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
139| AUTO_ROTATION                      |6 |表示传感器自动旋转模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
140| AUTO_ROTATION_LANDSCAPE            |7 |表示传感器自动横向旋转模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
141| AUTO_ROTATION_PORTRAIT             |8 |表示传感器自动竖向旋转模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
142| AUTO_ROTATION_RESTRICTED           |9 |表示受开关控制的自动旋转模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
143| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|表述受开关控制的自动横向旋转模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
144| AUTO_ROTATION_PORTRAIT_RESTRICTED  |11|表示受开关控制的自动竖向旋转模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
145| LOCKED                             |12|表示锁定模式。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
146| AUTO_ROTATION_UNSPECIFIED<sup>12+</sup> |13|受开关控制和由系统判定的自动旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
147| FOLLOW_DESKTOP<sup>12+</sup> |14|跟随桌面的旋转模式。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
148
149### CompatiblePolicy<sup>10+</sup>
150
151标识共享库的版本兼容类型。
152
153 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
154
155 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core
156
157| 名称                   | 值   | 说明                             |
158| ---------------------- | ---- | -------------------------------- |
159| BACKWARD_COMPATIBILITY | 1    | 该字段表明共享库是向后兼容类型。 |
160
161### ModuleType
162
163标识模块类型。
164
165 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
166
167 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core
168
169| 名称    | 值   | 说明                 |
170| ------- | ---- | -------------------- |
171| ENTRY   | 1    | 应用的主模块。   |
172| FEATURE | 2    | 应用的动态特性模块。 |
173| SHARED  | 3    | 应用的动态共享库模块。  |
174
175### BundleType
176
177标识应用的类型。
178
179 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
180
181 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core
182
183| 名称           | 值   | 说明            |
184| -------------- | ---- | --------------- |
185| APP            | 0    | 该Bundle是应用。    |
186| ATOMIC_SERVICE | 1    | 该Bundle是原子化服务。 |
187
188### MultiAppModeType<sup>12+</sup>
189标识应用多开的模式类型。
190
191 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core192
193| 名称 | 值 | 说明 |
194|:----------------:|:---:|:---:|
195| UNSPECIFIED|  0 | 未指定类型。 |
196| MULTI_INSTANCE |  1  | 多实例模式。常驻进程不支持该字段。  |
197| APP_CLONE |  2  |  分身模式。  |
198
199## 接口
200
201### bundleManager.getBundleInfoForSelf
202
203getBundleInfoForSelf(bundleFlags: number): Promise\<BundleInfo>
204
205以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用Promise形式返回结果。
206
207**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
208
209**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
210
211**参数:**
212
213| 参数名     | 类型   | 必填 | 说明                |
214| ----------- | ------ | ---- | --------------------- |
215| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是   | 指定返回的BundleInfo所包含的信息。 |
216
217**返回值:**
218
219| 类型                                                        | 说明                                  |
220| ----------------------------------------------------------- | ------------------------------------- |
221| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回当前应用的BundleInfo。|
222
223**错误码:**
224
225以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
226
227| 错误码ID | 错误信息                                                     |
228| -------- | ------------------------------------------------------------ |
229| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
230
231**示例:**
232
233```ts
234// 额外获取带有metadataArray信息的appInfo
235import { bundleManager } from '@kit.AbilityKit';
236import { BusinessError } from '@kit.BasicServicesKit';
237import { hilog } from '@kit.PerformanceAnalysisKit';
238
239let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
240
241try {
242  bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
243    hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
244  }).catch((err: BusinessError) => {
245    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
246  });
247} catch (err) {
248  let message = (err as BusinessError).message;
249  hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
250}
251```
252
253### bundleManager.getBundleInfoForSelf
254
255getBundleInfoForSelf(bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void
256
257以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用callback形式返回结果。
258
259**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
260
261**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
262
263**参数:**
264
265| 参数名     | 类型   | 必填 | 说明                |
266| ----------- | ------ | ---- | --------------------- |
267| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是   | 指定返回的BundleInfo所包含的信息。 |
268| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的当前应用的BundleInfo;否则为错误对象。 |
269
270**错误码:**
271
272以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
273
274| 错误码ID | 错误信息                                                     |
275| -------- | ------------------------------------------------------------ |
276| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
277
278**示例:**
279
280```ts
281// 额外获取带有permissions信息的abilitiesInfo
282import { bundleManager } from '@kit.AbilityKit';
283import { BusinessError } from '@kit.BasicServicesKit';
284import { hilog } from '@kit.PerformanceAnalysisKit';
285
286let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
287
288try {
289  bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
290    if (err) {
291      hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
292    } else {
293      hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data));
294    }
295  });
296} catch (err) {
297  let message = (err as BusinessError).message;
298  hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message);
299}
300```
301
302### bundleManager.getProfileByAbility
303
304getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void
305
306以异步方法根据给定的moduleName、abilityName和metadataName(module.json中[metadata标签](../../quick-start/module-configuration-file.md#metadata标签)下的name)获取相应配置文件的json格式字符串,使用callback形式返回结果。
307
308>如果配置文件信息采用了资源引用格式,则返回值将保持资源引用格式(例如 $string:res_id),开发者可以通过资源管理模块的相关接口,来获取引用的资源。
309
310**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
311
312**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
313
314**参数:**
315
316| 参数名       | 类型                          | 必填 | 说明                                                         |
317| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
318| moduleName   | string                        | 是   | 表示Module名称。                                     |
319| abilityName  | string                        | 是   | 表示UIAbility组件的名称。                                    |
320| metadataName | string                        | 是   | 表示UIAbility组件的元信息名称,即module.json5配置文件中abilities标签下的metadata标签的name。                                  |
321| callback     | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
322
323**错误码:**
324
325以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
326
327| 错误码ID | 错误信息                                                     |
328| -------- | ------------------------------------------------------------ |
329| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
330| 17700002 | The specified moduleName is not existed.                      |
331| 17700003 | The specified abilityName is not existed.                     |
332| 17700024 | Failed to get the profile because there is no profile in the HAP. |
333| 17700026 | The specified bundle is disabled.                             |
334| 17700029 | The specified ability is disabled.                            |
335
336**示例:**
337
338```ts
339import { bundleManager } from '@kit.AbilityKit';
340import { BusinessError } from '@kit.BasicServicesKit';
341import { hilog } from '@kit.PerformanceAnalysisKit';
342
343let moduleName = 'entry';
344let abilityName = 'EntryAbility';
345let metadataName = 'ability_metadata';
346
347try {
348  bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
349    if (err) {
350      hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
351    } else {
352      hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data));
353    }
354  });
355} catch (err) {
356  let message = (err as BusinessError).message;
357  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
358}
359```
360
361### bundleManager.getProfileByAbility
362
363getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string\>\>
364
365以异步方法根据给定的moduleName、abilityName和metadataName(module.json中[metadata标签](../../quick-start/module-configuration-file.md#metadata标签)下的name)获取相应配置文件的json格式字符串,使用Promise形式返回结果。
366
367>如果配置文件信息采用了资源引用格式,则返回值将保持资源引用格式(例如 $string:res_id),开发者可以通过资源管理模块的相关接口,来获取引用的资源。
368
369**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
370
371**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
372
373**参数:**
374
375| 参数名       | 类型   | 必填 | 说明                       |
376| ------------ | ------ | ---- | -------------------------- |
377| moduleName   | string | 是   | 表示Module名称。   |
378| abilityName  | string | 是   | 表示UIAbility组件的名称。  |
379| metadataName | string | 否   | 表示UIAbility组件的元信息名称,即module.json5配置文件中abilities标签下的metadata标签的name,默认值为空。 |
380
381**返回值:**
382
383| 类型                    | 说明                            |
384| ----------------------- | ------------------------------- |
385| Promise<Array\<string>> | Promise对象,返回Array\<string>。 |
386
387**错误码:**
388
389以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
390
391| 错误码ID | 错误信息                                                     |
392| -------- | ------------------------------------------------------------ |
393| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
394| 17700002 | The specified moduleName is not existed.                      |
395| 17700003 | The specified abilityName is not existed.                     |
396| 17700024 | Failed to get the profile because there is no profile in the HAP. |
397| 17700026 | The specified bundle is disabled.                             |
398| 17700029 | The specified ability is disabled.                            |
399
400**示例:**
401
402```ts
403import { bundleManager } from '@kit.AbilityKit';
404import { BusinessError } from '@kit.BasicServicesKit';
405import { hilog } from '@kit.PerformanceAnalysisKit';
406
407let moduleName = 'entry';
408let abilityName = 'EntryAbility';
409
410try {
411  bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
412    hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
413  }).catch((err: BusinessError) => {
414    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
415  });
416} catch (err) {
417  let message = (err as BusinessError).message;
418  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
419}
420```
421
422```ts
423import { bundleManager } from '@kit.AbilityKit';
424import { BusinessError } from '@kit.BasicServicesKit';
425import { hilog } from '@kit.PerformanceAnalysisKit';
426
427let moduleName = 'entry';
428let abilityName = 'EntryAbility';
429let metadataName = 'ability_metadata';
430
431try {
432  bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
433    hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
434  }).catch((err: BusinessError) => {
435    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
436  });
437} catch (err) {
438  let message = (err as BusinessError).message;
439  hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', message);
440}
441```
442
443### bundleManager.getProfileByAbilitySync<sup>10+</sup>
444
445getProfileByAbilitySync(moduleName: string, abilityName: string, metadataName?: string): Array\<string\>
446
447以同步方法根据给定的moduleName、abilityName和metadataName(module.json中[metadata标签](../../quick-start/module-configuration-file.md#metadata标签)下的name)获取相应配置文件的json格式字符串,返回对象为string数组。
448
449>如果配置文件信息采用了资源引用格式,则返回值将保持资源引用格式(例如 $string:res_id),开发者可以通过资源管理模块的相关接口,来获取引用的资源。
450
451**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
452
453**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
454
455**参数:**
456
457| 参数名       | 类型   | 必填 | 说明                       |
458| ------------ | ------ | ---- | -------------------------- |
459| moduleName   | string | 是   | 表示Module名称。   |
460| abilityName  | string | 是   | 表示UIAbility组件的名称。  |
461| metadataName | string | 否   | 表示UIAbility组件的元信息名称,即module.json5配置文件中abilities标签下的metadata标签的name,默认值为空。 |
462
463**返回值:**
464
465| 类型                    | 说明                            |
466| ----------------------- | ------------------------------- |
467| Array\<string> | 数组对象,返回Array\<string>。 |
468
469**错误码:**
470
471以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
472
473| 错误码ID | 错误信息                                                     |
474| -------- | ------------------------------------------------------------ |
475| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
476| 17700002 | The specified moduleName is not existed.                      |
477| 17700003 | The specified abilityName is not existed.                     |
478| 17700024 | Failed to get the profile because there is no profile in the HAP. |
479| 17700026 | The specified bundle is disabled.                             |
480| 17700029 | The specified ability is disabled.                            |
481
482**示例:**
483
484```ts
485import { bundleManager } from '@kit.AbilityKit';
486import { BusinessError } from '@kit.BasicServicesKit';
487import { hilog } from '@kit.PerformanceAnalysisKit';
488
489let moduleName = 'entry';
490let abilityName = 'EntryAbility';
491
492try {
493  let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName);
494  hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
495} catch (err) {
496  let message = (err as BusinessError).message;
497  hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message);
498}
499```
500
501```ts
502import { bundleManager } from '@kit.AbilityKit';
503import { BusinessError } from '@kit.BasicServicesKit';
504import { hilog } from '@kit.PerformanceAnalysisKit';
505
506let moduleName: string = 'entry';
507let abilityName: string = 'EntryAbility';
508let metadataName: string = 'ability_metadata';
509
510try {
511  let data = bundleManager.getProfileByAbilitySync(moduleName, abilityName, metadataName);
512  hilog.info(0x0000, 'testTag', 'getProfileByAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
513} catch (err) {
514  let message = (err as BusinessError).message;
515  hilog.error(0x0000, 'testTag', 'getProfileByAbilitySync failed. Cause: %{public}s', message);
516}
517```
518
519### bundleManager.getProfileByExtensionAbility
520
521getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void
522
523以异步方法根据给定的moduleName、extensionAbilityName和metadataName(module.json中[metadata标签](../../quick-start/module-configuration-file.md#metadata标签)下的name)获取相应配置文件的json格式字符串,使用callback形式返回结果。
524
525>如果配置文件信息采用了资源引用格式,则返回值将保持资源引用格式(例如 $string:res_id),开发者可以通过资源管理模块的相关接口,来获取引用的资源。
526
527**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
528
529**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
530
531**参数:**
532
533| 参数名                 | 类型                          | 必填 | 说明                                                         |
534| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ |
535| moduleName           | string                        | 是   | 表示Module名称。                                   |
536| extensionAbilityName | string                        | 是   | 表示ExtensionAbility组件的名称。                         |
537| metadataName         | string                        | 是   | 表示ExtensionAbility组件的名称。组件的元信息名称,即module.json5配置文件中extensionAbilities标签下的metadata标签的name。                                 |
538| callback             | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
539
540**错误码:**
541
542以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
543
544| 错误码ID | 错误信息                                                     |
545| -------- | ------------------------------------------------------------ |
546| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
547| 17700002 | The specified moduleName is not existed.                      |
548| 17700003 | The specified extensionAbilityName not existed.            |
549| 17700024 | Failed to get the profile because there is no profile in the HAP. |
550| 17700026 | The specified bundle is disabled.                             |
551
552**示例:**
553
554```ts
555import { bundleManager } from '@kit.AbilityKit';
556import { BusinessError } from '@kit.BasicServicesKit';
557import { hilog } from '@kit.PerformanceAnalysisKit';
558
559let moduleName = 'entry';
560let extensionAbilityName = 'com.example.myapplication.extension';
561let metadataName = 'ability_metadata';
562
563try {
564  bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => {
565    if (err) {
566      hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
567    } else {
568      hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data));
569    }
570  });
571} catch (err) {
572  let message = (err as BusinessError).message;
573  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', message);
574}
575```
576
577### bundleManager.getProfileByExtensionAbility
578
579getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string\>\>
580
581以异步方法根据给定的moduleName、extensionAbilityName和metadataName(module.json中[metadata标签](../../quick-start/module-configuration-file.md#metadata标签)下的name)获取相应配置文件的json格式字符串,使用Promise形式返回结果。
582
583>如果配置文件信息采用了资源引用格式,则返回值将保持资源引用格式(例如 $string:res_id),开发者可以通过资源管理模块的相关接口,来获取引用的资源。
584
585**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
586
587**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
588
589**参数:**
590
591| 参数名                 | 类型   | 必填 | 说明                               |
592| -------------------- | ------ | ---- | ---------------------------------- |
593| moduleName           | string | 是   | 表示Module名称。           |
594| extensionAbilityName | string | 是   | 表示ExtensionAbility组件的名称。 |
595| metadataName         | string | 否   | 表示ExtensionAbility组件的名称。组件的元信息名称,即module.json5配置文件中extensionAbilities标签下的metadata标签的name,默认值为空。         |
596
597**返回值:**
598
599| 类型                    | 说明                                |
600| ----------------------- | ----------------------------------- |
601| Promise<Array\<string>> | Promise对象,返回Array\<string>对象。 |
602
603**错误码:**
604
605以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
606
607| 错误码ID | 错误信息                                                     |
608| -------- | ------------------------------------------------------------ |
609| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
610| 17700002 | The specified moduleName is not existed.                      |
611| 17700003 | The specified extensionAbilityName not existed.            |
612| 17700024 | Failed to get the profile because there is no profile in the HAP. |
613| 17700026 | The specified bundle is disabled.                             |
614
615**示例:**
616
617```ts
618import { bundleManager } from '@kit.AbilityKit';
619import { BusinessError } from '@kit.BasicServicesKit';
620import { hilog } from '@kit.PerformanceAnalysisKit';
621
622let moduleName = 'entry';
623let extensionAbilityName = 'com.example.myapplication.extension';
624let metadataName = 'ability_metadata';
625
626try {
627  bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
628    hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
629  }).catch((err: BusinessError) => {
630    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
631  });
632} catch (err) {
633  let message = (err as BusinessError).message;
634  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', message);
635}
636
637try {
638  bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).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```
648
649### bundleManager.getProfileByExtensionAbilitySync<sup>10+</sup>
650
651getProfileByExtensionAbilitySync(moduleName: string, extensionAbilityName: string, metadataName?: string): Array\<string\>
652
653以同步方法根据给定的moduleName、extensionAbilityName和metadataName(module.json中[metadata标签](../../quick-start/module-configuration-file.md#metadata标签)下的name)获取相应配置文件的json格式字符串,返回对象为string数组。
654
655>如果配置文件信息采用了资源引用格式,则返回值将保持资源引用格式(例如 $string:res_id),开发者可以通过资源管理模块的相关接口,来获取引用的资源。
656
657**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
658
659**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
660
661**参数:**
662
663| 参数名                 | 类型   | 必填 | 说明                               |
664| -------------------- | ------ | ---- | ---------------------------------- |
665| moduleName           | string | 是   | 表示Module名称。           |
666| extensionAbilityName | string | 是   | 表示ExtensionAbility组件的名称。 |
667| metadataName         | string | 否   | 表示ExtensionAbility组件的名称。组件的元信息名称,即module.json5配置文件中extensionAbilities标签下的metadata标签的name,默认值为空。         |
668
669**返回值:**
670
671| 类型                    | 说明                                |
672| ----------------------- | ----------------------------------- |
673| Array\<string> | 返回Array\<string>对象。 |
674
675**错误码:**
676
677以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
678
679| 错误码ID | 错误信息                                                     |
680| -------- | ------------------------------------------------------------ |
681| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
682| 17700002 | The specified moduleName is not existed.                      |
683| 17700003 | The specified extensionAbilityName not existed.            |
684| 17700024 | Failed to get the profile because there is no profile in the HAP. |
685| 17700026 | The specified bundle is disabled.                             |
686
687**示例:**
688
689```ts
690import { bundleManager } from '@kit.AbilityKit';
691import { BusinessError } from '@kit.BasicServicesKit';
692import { hilog } from '@kit.PerformanceAnalysisKit';
693
694let moduleName = 'entry';
695let extensionAbilityName = 'com.example.myapplication.extension';
696let metadataName = 'ability_metadata';
697
698try {
699  let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName);
700  hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
701} catch (err) {
702  let message = (err as BusinessError).message;
703  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message);
704}
705
706try {
707  let data = bundleManager.getProfileByExtensionAbilitySync(moduleName, extensionAbilityName, metadataName);
708  hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbilitySync successfully. Data: %{public}s', JSON.stringify(data));
709} catch (err) {
710  let message = (err as BusinessError).message;
711  hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbilitySync failed. Cause: %{public}s', message);
712}
713```
714
715### bundleManager.getBundleInfoForSelfSync<sup>10+</sup>
716
717getBundleInfoForSelfSync(bundleFlags: number): BundleInfo
718
719以同步方法根据给定的bundleFlags获取当前应用的BundleInfo。
720
721**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
722
723**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
724
725**参数:**
726
727| 参数名     | 类型   | 必填 | 说明                |
728| ----------- | ------ | ---- | --------------------- |
729| [bundleFlags](js-apis-bundleManager.md#bundleflag) | number | 是   | 指定返回的BundleInfo所包含的信息。 |
730
731**返回值:**
732
733| 类型                                              | 说明                 |
734| ------------------------------------------------- | -------------------- |
735| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 |
736
737**错误码:**
738
739以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
740
741| 错误码ID | 错误信息                                                     |
742| -------- | ------------------------------------------------------------ |
743| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
744
745**示例:**
746
747```ts
748import { bundleManager } from '@kit.AbilityKit';
749import { BusinessError } from '@kit.BasicServicesKit';
750import { hilog } from '@kit.PerformanceAnalysisKit';
751
752let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
753
754try {
755  let data = bundleManager.getBundleInfoForSelfSync(bundleFlags);
756  hilog.info(0x0000, 'testTag', 'getBundleInfoForSelfSync successfully: %{public}s', JSON.stringify(data));
757} catch (err) {
758  let message = (err as BusinessError).message;
759  hilog.error(0x0000, 'testTag', 'getBundleInfoForSelfSync failed: %{public}s', message);
760}
761```
762
763### bundleManager.canOpenLink<sup>12+</sup>
764
765canOpenLink(link: string): boolean
766
767查询给定的链接是否可以打开。指定链接的scheme需要在module.json文件的querySchemes字段下配置。
768
769**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
770
771**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
772
773**参数:**
774
775| 参数名     | 类型   | 必填 | 说明                |
776| ----------- | ------ | ---- | --------------------- |
777| link | string | 是   | 表示需要查询的链接。 |
778
779**返回值:**
780
781| 类型                                              | 说明                 |
782| ------------------------------------------------- | -------------------- |
783| boolean | 返回true表示给定的链接可以打开,返回false表示给定的链接不能打开。 |
784
785**错误码:**
786
787以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。
788
789| 错误码ID | 错误信息                                                     |
790| -------- | ------------------------------------------------------------ |
791| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
792| 17700055 | The specified link is invalid.                      |
793| 17700056 | The scheme of the specified link is not in the querySchemes.        |
794
795**示例:**
796
797```ts
798import { bundleManager } from '@kit.AbilityKit';
799import { BusinessError } from '@kit.BasicServicesKit';
800import { hilog } from '@kit.PerformanceAnalysisKit';
801
802try {
803  let link = 'welink://';
804  let data = bundleManager.canOpenLink(link);
805  hilog.info(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));
806} catch (err) {
807  let message = (err as BusinessError).message;
808  hilog.error(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);
809}
810```
811
812### bundleManager.getLaunchWant<sup>13+</sup>
813
814getLaunchWant(): Want
815
816获取自身用于启动应用程序的Want参数。
817
818**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
819
820**系统能力:** SystemCapability.BundleManager.BundleFramework.Core
821
822**返回值:**
823
824| 类型                                | 说明                                        |
825| ----------------------------------- | ------------------------------------------- |
826| [Want](js-apis-app-ability-want.md) | 返回包含Bundle名称和Ability名称的Want对象。 |
827
828**错误码:**
829
830以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。
831
832| 错误码ID | 错误信息                      |
833| -------- | ----------------------------- |
834| 17700072 | The launch want is not found. |
835
836**示例:**
837
838```ts
839import { BusinessError } from '@kit.BasicServicesKit';
840import { bundleManager } from '@kit.AbilityKit';
841import { hilog } from '@kit.PerformanceAnalysisKit';
842
843try {
844  let want = bundleManager.getLaunchWant();
845  hilog.info(0x0000, 'testTag', 'getLaunchWant ability name: %{public}s', want.abilityName);
846  hilog.info(0x0000, 'testTag', 'getLaunchWant bundle name: %{public}s', want.bundleName);
847} catch (error) {
848  let message = (error as BusinessError).message;
849  hilog.error(0x0000, 'testTag', 'getLaunchWant failed: %{public}s', message);
850}
851```