js-apis-bundleManager.md 131.1 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.bundle.bundleManager (bundleManager模块)
W
wanghang 已提交
2 3 4

本模块提供应用信息查询能力,支持BundleInfo、ApplicationInfo、Ability、ExtensionAbility等信息的查询

zyjhandsome's avatar
zyjhandsome 已提交
5
> **说明:**
W
wanghang 已提交
6 7 8 9 10
> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

## 导入模块

```ts
L
Lotol 已提交
11
import bundleManager from '@ohos.bundle.bundleManager';
W
wanghang 已提交
12
```
W
wtt1995 已提交
13

W
wanghang 已提交
14 15
## 权限列表

J
junyi233 已提交
16
| 权限                                       | 权限等级     | 描述            |
W
wanghang 已提交
17
| ------------------------------------------ | ------------ | ------------------|
Z
zhaogan 已提交
18 19 20 21
| ohos.permission.GET_BUNDLE_INFO            | normal       | 查询指定应用信息。   |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | 可查询所有应用信息。 |
| ohos.permission.REMOVE_CACHE_FILES         | system_basic | 清理应用缓存。       |
|ohos.permission.CHANGE_ABILITY_ENABLED_STATE| system_basic | 设置禁用使能所需的权限。  |
W
wanghang 已提交
22

Z
zengyawen 已提交
23
权限等级参考[权限等级说明](../../security/accesstoken-overview.md#权限等级说明)
W
wanghang 已提交
24 25 26 27 28

## 枚举

### BundleFlag

Z
zhaogan 已提交
29 30
包信息标志,指示需要获取的包信息的内容。

W
wtt1995 已提交
31
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
32 33 34

| 名称                                      | 值         | 说明                                                         |
| ----------------------------------------- | ---------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
35 36 37 38
| GET_BUNDLE_INFO_DEFAULT                   | 0x00000000 | 用于获取默认bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 |
| GET_BUNDLE_INFO_WITH_APPLICATION          | 0x00000001 | 用于获取包含applicationInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 |
| GET_BUNDLE_INFO_WITH_HAP_MODULE           | 0x00000002 | 用于获取包含hapModuleInfo的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability、extensionAbility和permission的信息。 |
| GET_BUNDLE_INFO_WITH_ABILITY              | 0x00000004 | 用于获取包含ability的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、extensionAbility和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 |
W
wanghang 已提交
39
| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY    | 0x00000008 | 用于获取包含extensionAbility的bundleInfo,获取的bundleInfo不包含signatureInfo、applicationInfo、ability 和permission的信息。它不能单独使用,需要与GET_BUNDLE_INFO_WITH_HAP_MODULE一起使用。 |
Z
zhaogan 已提交
40 41 42 43
| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION | 0x00000010 | 用于获取包含permission的bundleInfo。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、extensionAbility和ability的信息。 |
| 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一起使用。 |
| GET_BUNDLE_INFO_WITH_DISABLE              | 0x00000040 | 用于获取application被禁用的BundleInfo和被禁用的Ability信息。获取的bundleInfo不包含signatureInfo、applicationInfo、hapModuleInfo、ability、extensionAbility和permission的信息。 |
| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO       | 0x00000080 | 用于获取包含signatureInfo的bundleInfo。获取的bundleInfo不包含applicationInfo、hapModuleInfo、extensionAbility、ability和permission的信息。 |
W
wanghang 已提交
44 45 46

### ApplicationFlag

Z
zhaogan 已提交
47 48
应用信息标志,指示需要获取的应用信息的内容。

W
wtt1995 已提交
49
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
50

51
 **系统接口:** 此接口为系统接口。
W
wanghang 已提交
52 53 54

| 名称                                 | 值         | 说明                                                         |
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
55 56 57 58
| GET_APPLICATION_INFO_DEFAULT         | 0x00000000 | 用于获取默认的applicationInfo,获取的applicationInfo不包含permission和metadata信息。 |
| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000001 | 用于获取包含permission的applicationInfo。                    |
| GET_APPLICATION_INFO_WITH_METADATA   | 0x00000002 | 用于获取包含metadata的applicationInfo。                      |
| GET_APPLICATION_INFO_WITH_DISABLE    | 0x00000004 | 用于获取包含禁用应用程序的applicationInfo。                  |
W
wanghang 已提交
59 60 61

### AbilityFlag

W
wtt1995 已提交
62
Ability组件信息标志,指示需要获取的Ability组件信息的内容。
Z
zhaogan 已提交
63

W
wtt1995 已提交
64
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
65

66
 **系统接口:** 此接口为系统接口。
W
wanghang 已提交
67 68 69

| 名称                              | 值         | 说明                                                         |
| --------------------------------- | ---------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
70 71 72 73 74 75
| GET_ABILITY_INFO_DEFAULT          | 0x00000000 | 用于获取默认abilityInfo,获取的abilityInfo不包含permission、metadata和禁用的abilityInfo。 |
| GET_ABILITY_INFO_WITH_PERMISSION  | 0x00000001 | 用于获取包含permission的abilityInfo。                          |
| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的abilityInfo。                     |
| GET_ABILITY_INFO_WITH_METADATA    | 0x00000004 | 用于获取包含metadata的abilityInfo。                            |
| GET_ABILITY_INFO_WITH_DISABLE     | 0x00000008 | 用于获取包含禁用的abilityInfo的abilityInfo。                   |
| GET_ABILITY_INFO_ONLY_SYSTEM_APP  | 0x00000010 | 用于仅为系统应用程序获取abilityInfo。                         |
W
wanghang 已提交
76 77 78

### ExtensionAbilityFlag

Z
zhaogan 已提交
79 80
扩展组件信息标志,指示需要获取的扩展组件信息的内容。

W
wtt1995 已提交
81
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
82

83
 **系统接口:** 此接口为系统接口。
W
wanghang 已提交
84 85 86

| 名称                                        | 值         | 说明                                                         |
| ------------------------------------------- | ---------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
87 88 89 90
| GET_EXTENSION_ABILITY_INFO_DEFAULT          | 0x00000000 | 用于获取默认extensionAbilityInfo。获取的extensionAbilityInfo不包含permission、metadata 和禁用的abilityInfo。 |
| GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION  | 0x00000001 | 用于获取包含permission的extensionAbilityInfo。               |
| GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | 用于获取包含applicationInfo的extensionAbilityInfo。         |
| GET_EXTENSION_ABILITY_INFO_WITH_METADATA    | 0x00000004 | 用于获取包含metadata的extensionAbilityInfo。                 |
W
wanghang 已提交
91 92 93

### ExtensionAbilityType

Z
zhaogan 已提交
94 95
指示扩展组件的类型。

W
wtt1995 已提交
96
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
97

J
junyi233 已提交
98
| 名称 | 值 | 说明 |
Z
zhongjianfei 已提交
99
|:----------------:|:---:|-----|
Z
zhongjianfei 已提交
100
| FORM             | 0   | [FormExtensionAbility](../../application-models/widget-development-stage.md):卡片扩展能力,提供卡片开发能力。 |
Z
zhongjianfei 已提交
101 102
| WORK_SCHEDULER   | 1   | [WorkSchedulerExtensionAbility](../../task-management/work-scheduler-dev-guide.md):延时任务扩展能力,允许应用在系统闲时执行实时性不高的任务。 |
| INPUT_METHOD     | 2   | [InputMethodExtensionAbility](js-apis-inputmethod-extension-ability.md):输入法扩展能力,用于开发输入法应用。 |
Z
zhongjianfei 已提交
103
| SERVICE          | 3   | [ServiceExtensionAbility](../../application-models/serviceextensionability.md):后台服务扩展能力,提供后台运行并对外提供相应能力。 |
Z
zhongjianfei 已提交
104
| ACCESSIBILITY    | 4   | [AccessibilityExtensionAbility](js-apis-application-accessibilityExtensionAbility.md):无障碍服务扩展能力,支持访问与操作前台界面。 |
Z
zhongjianfei 已提交
105 106 107 108 109
| DATA_SHARE       | 5   | [DataShareExtensionAbility](../../database/database-datashare-guidelines.md):数据共享扩展能力,用于对外提供数据读写服务。 |
| FILE_SHARE       | 6   | FileShareExtensionAbility:文件共享扩展能力,用于应用间的文件分享。预留能力,当前暂未支持。 |
| STATIC_SUBSCRIBER| 7   | [StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md):静态广播扩展能力,用于处理静态事件,比如开机事件。 |
| WALLPAPER        | 8   | WallpaperExtensionAbility:壁纸扩展能力,用于实现桌面壁纸。预留能力,当前暂未支持。 |
| BACKUP           |  9  | BackupExtensionAbility:数据备份扩展能力,提供应用数据和公共数据备份回复能力。预留能力,当前暂未支持。 |
Z
zhongjianfei 已提交
110
| WINDOW           |  10 | [WindowExtensionAbility](js-apis-application-windowExtensionAbility.md):界面组合扩展能力,允许系统应用进行跨应用的界面拉起和嵌入。 |
Z
zhongjianfei 已提交
111 112 113
| ENTERPRISE_ADMIN |  11 | [EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md):企业设备管理扩展能力,提供企业管理时处理管理事件的能力,比如设备上应用安装事件、锁屏密码输入错误次数过多事件等。 |
| THUMBNAIL        | 13  | ThumbnailExtensionAbility:文件缩略图扩展能力,用于为文件提供图标缩略图的能力。预留能力,当前暂未支持。 |
| PREVIEW          | 14  | PreviewExtensionAbility:文件预览扩展能力,提供文件预览的能力,其他应用可以直接在应用中嵌入显示。预留能力,当前暂未支持。 |
114
| PRINT<sup>10+</sup> | 15 | PrintExtensionAbility:文件打印扩展能力,提供应用打印照片、文档等办公场景。当前支持图片打印,文档类型暂未支持。 |
Z
zhongjianfei 已提交
115
| UNSPECIFIED      | 255 | 不指定类型,配合queryExtensionAbilityInfo接口可以查询所有类型的ExtensionAbility。 |
W
wanghang 已提交
116 117 118 119


### PermissionGrantState

W
wtt1995 已提交
120
指示权限授予状态。
Z
zhaogan 已提交
121

W
wtt1995 已提交
122
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
123

J
junyi233 已提交
124 125
| 名称 | 值 | 说明 |
|:----------------:|:---:|:---:|
Z
zhaogan 已提交
126 127
| PERMISSION_DENIED|  -1 | 拒绝授予权限。 |
| PERMISSION_GRANTED |  0  |  授予权限。  |
W
wanghang 已提交
128 129 130

### SupportWindowMode

Z
zhaogan 已提交
131 132
标识该组件所支持的窗口模式。

W
wtt1995 已提交
133
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
134

J
junyi233 已提交
135 136
| 名称 | 值 | 说明 |
|:----------------:|:---:|:---:|
Z
zhaogan 已提交
137 138 139
| FULL_SCREEN      | 0   | 窗口支持全屏显示。 |
| SPLIT            | 1   | 窗口支持分屏显示。 |
| FLOATING         | 2   | 支持窗口化显示。   |
W
wanghang 已提交
140 141 142

### LaunchType

Z
zhaogan 已提交
143 144
指示组件的启动方式。

W
wtt1995 已提交
145
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
146

J
junyi233 已提交
147 148
| 名称 | 值 | 说明 |
|:----------------:|:---:|:---:|
W
wtt1995 已提交
149
| SINGLETON        | 0   | ability的启动模式,表示单实例。 |
W
wangtiantian 已提交
150
| MULTITON         | 1   | ability的启动模式,表示普通多实例。 |
W
wtt1995 已提交
151
| SPECIFIED        | 2   | ability的启动模式,表示该ability内部根据业务自己置顶多实例。 |
W
wanghang 已提交
152 153 154

### AbilityType

Z
zhaogan 已提交
155 156
指示Ability组件的类型。

W
wtt1995 已提交
157
 **模型约束:** 仅可在FA模型下使用
W
wanghang 已提交
158

W
wtt1995 已提交
159
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
160

J
junyi233 已提交
161 162
|  名称   | 值   |                            说明                            |
| :-----: | ---- | :--------------------------------------------------------: |
Z
zhaogan 已提交
163 164 165
|  PAGE   | 1    |     表示基于Page模板开发的FA,用于提供与用户交互的能力。     |
| SERVICE | 2    |  表示基于Service模板开发的PA,用于提供后台运行任务的能力。   |
|  DATA   | 3    | 表示基于Data模板开发的PA,用于对外部提供统一的数据访问对象。 |
W
wanghang 已提交
166 167 168

### DisplayOrientation

Z
zhaogan 已提交
169 170
标识该Ability的显示模式。该标签仅适用于page类型的Ability。

W
wtt1995 已提交
171
 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
172

J
junyi233 已提交
173 174
| 名称                               |值 |说明 |
|:----------------------------------|---|---|
Z
zhaogan 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187
| UNSPECIFIED                        |0 |表示未定义方向模式,由系统判定。 |
| LANDSCAPE                          |1 |表示横屏显示模式。 |
| PORTRAIT                           |2 |表示竖屏显示模式。 |
| FOLLOW_RECENT                      |3 |表示跟随上一个显示模式。 |
| LANDSCAPE_INVERTED                 |4 |表示反向横屏显示模式。 |
| PORTRAIT_INVERTED                  |5 |表示反向竖屏显示模式。 |
| AUTO_ROTATION                      |6 |表示传感器自动旋转模式。 |
| AUTO_ROTATION_LANDSCAPE            |7 |表示传感器自动横向旋转模式。 |
| AUTO_ROTATION_PORTRAIT             |8 |表示传感器自动竖向旋转模式。 |
| AUTO_ROTATION_RESTRICTED           |9 |表示受开关控制的自动旋转模式。 |
| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|表述受开关控制的自动横向旋转模式。|
| AUTO_ROTATION_PORTRAIT_RESTRICTED  |11|表示受开关控制的自动竖向旋转模式。|
| LOCKED                             |12|表示锁定模式。|
W
wanghang 已提交
188

X
xsz233 已提交
189
### CompatiblePolicy<sup>10+</sup>
Z
zhaogan 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

标识共享库的版本兼容类型。

 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core

| 名称                   | 值   | 说明                             |
| ---------------------- | ---- | -------------------------------- |
| BACKWARD_COMPATIBILITY | 1    | 该字段表明共享库是向后兼容类型。 |

### ModuleType

标识模块类型。

 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core

| 名称    | 值   | 说明                 |
| ------- | ---- | -------------------- |
| ENTRY   | 1    | 应用的主模块。   |
| FEATURE | 2    | 应用的动态特性模块。 |
| SHARED  | 3    | 应用的动态共享库模块。  |

### BundleType

标识应用的类型。

 **系统能力:** 以下各项对应的系统能力均为SystemCapability.BundleManager.BundleFramework.Core

| 名称           | 值   | 说明            |
| -------------- | ---- | --------------- |
| APP            | 0    | 该Bundle是普通应用程序。    |
| ATOMIC_SERVICE | 1    | 该Bundle是原子化服务。 |

W
wtt1995 已提交
222
## 接口
W
wanghang 已提交
223 224 225 226 227 228 229 230 231 232 233

### bundleManager.getBundleInfoForSelf

getBundleInfoForSelf(bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>;

以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用Promise形式返回结果。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
234
| 参数名     | 类型   | 必填 | 说明                |
W
wanghang 已提交
235
| ----------- | ------ | ---- | --------------------- |
Z
zhaogan 已提交
236
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。 |
W
wanghang 已提交
237 238 239 240 241

**返回值:**

| 类型                                                        | 说明                                  |
| ----------------------------------------------------------- | ------------------------------------- |
Z
zhaogan 已提交
242
| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回当前应用的BundleInfo。|
W
wanghang 已提交
243

Z
zhaogan 已提交
244 245
**示例:**

W
wanghang 已提交
246
```ts
L
Lotol 已提交
247
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
248
import hilog from '@ohos.hilog';
W
wanghang 已提交
249 250 251
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
    bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
G
geng-wenguang 已提交
252
        hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
253 254
    }).catch(err => {
        hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
W
wanghang 已提交
255
    });
256 257
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
W
wanghang 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270
}
```

### bundleManager.getBundleInfoForSelf

getBundleInfoForSelf(bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void;

以异步方法根据给定的bundleFlags获取当前应用的BundleInfo,使用callback形式返回结果。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
271
| 参数名     | 类型   | 必填 | 说明                |
W
wanghang 已提交
272
| ----------- | ------ | ---- | --------------------- |
Z
zhaogan 已提交
273 274
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。 |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的当前应用的BundleInfo;否则为错误对象。 |
W
wanghang 已提交
275 276 277 278

**示例:**

```ts
L
Lotol 已提交
279
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
280
import hilog from '@ohos.hilog';
W
wanghang 已提交
281 282 283 284 285
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
        if (err) {
286
            hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
W
wanghang 已提交
287
        } else {
G
geng-wenguang 已提交
288
            hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
289 290 291
        }
    });
} catch (err) {
292
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
W
wanghang 已提交
293 294 295 296 297 298 299 300 301
}
```

### bundleManager.getBundleInfo

getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void;

以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用callback形式返回结果。

G
geng-wenguang 已提交
302 303
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
304 305 306 307 308 309 310 311
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
312
| 参数名  | 类型   | 必填 | 说明                       |
W
wanghang 已提交
313
| ----------- | ------ | ---- | ---------------------------- |
314
| bundleName  | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
315 316 317
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。|
| userId      | number | 是   | 表示用户ID。  |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的bundleInfo;否则为错误对象。 |
W
wanghang 已提交
318 319 320

**错误码:**

Z
zengyawen 已提交
321
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
322

J
junyi233 已提交
323
| 错误码ID | 错误信息                              |
W
wanghang 已提交
324
| -------- | ------------------------------------- |
Z
zhaogan 已提交
325
| 17700001 | The specified bundleName is not found. |
326
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
327
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
328 329 330 331

**示例:**

```ts
J
junyi233 已提交
332
// 额外获取AbilityInfo
L
Lotol 已提交
333
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
334
import hilog from '@ohos.hilog';
W
wanghang 已提交
335
let bundleName = 'com.example.myapplication';
J
junyi233 已提交
336 337 338 339 340 341
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY;
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
342
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
J
junyi233 已提交
343
        } else {
L
longwei 已提交
344
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
J
junyi233 已提交
345 346 347
        }
    });
} catch (err) {
L
longwei 已提交
348
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
J
junyi233 已提交
349 350 351
}
```

Z
zhaogan 已提交
352
```ts
J
junyi233 已提交
353
// 额外获取ApplicationInfo中的metadata
L
Lotol 已提交
354
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
355
import hilog from '@ohos.hilog';
J
junyi233 已提交
356 357
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
W
wanghang 已提交
358 359 360 361 362
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
363
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
364
        } else {
L
longwei 已提交
365
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
366 367 368
        }
    });
} catch (err) {
L
longwei 已提交
369
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
370 371 372 373 374 375 376 377 378
}
```

### bundleManager.getBundleInfo

getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void;

以异步方法根据给定的bundleName和bundleFlags获取BundleInfo,使用callback形式返回结果。

G
geng-wenguang 已提交
379 380
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
381 382 383 384 385 386 387 388
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
389
| 参数名     | 类型   | 必填 | 说明                       |
W
wanghang 已提交
390
| ----------- | ------ | ---- | ---------------------------- |
391
| bundleName  | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
392 393
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。|
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 |
W
wanghang 已提交
394 395 396

**错误码:**

Z
zengyawen 已提交
397
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
398

J
junyi233 已提交
399
| 错误码ID | 错误信息                              |
W
wanghang 已提交
400
| -------- | ------------------------------------- |
Z
zhaogan 已提交
401
| 17700001 | The specified bundleName is not found. |
402
| 17700004 | The specified user ID is not found.    |
Z
zhaogan 已提交
403
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
404 405 406 407

**示例:**

```ts
J
junyi233 已提交
408
// 额外获取extensionAbility
L
Lotol 已提交
409
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
410
import hilog from '@ohos.hilog';
W
wanghang 已提交
411
let bundleName = 'com.example.myapplication';
J
junyi233 已提交
412
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY;
W
wanghang 已提交
413 414 415 416

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => {
        if (err) {
L
longwei 已提交
417
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
418
        } else {
L
longwei 已提交
419
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
420 421 422
        }
    });
} catch (err) {
L
longwei 已提交
423
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
424 425 426 427 428 429 430 431 432
}
```

### bundleManager.getBundleInfo

getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: number): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>;

以异步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo,使用Promise形式返回结果。

G
geng-wenguang 已提交
433 434
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
435 436 437 438 439 440 441 442
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
443
| 参数名     | 类型   | 必填 | 说明                       |
W
wanghang 已提交
444
| ----------- | ------ | ---- | ---------------------------- |
445
| bundleName  | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
446 447
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。       |
| userId      | number | 否   | 表示用户ID。  |
W
wanghang 已提交
448 449 450 451 452

**返回值:**

| 类型                                                        | 说明                        |
| ----------------------------------------------------------- | --------------------------- |
Z
zhaogan 已提交
453
| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 |
W
wanghang 已提交
454 455 456

**错误码:**

Z
zengyawen 已提交
457
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
J
junyi233 已提交
458

J
junyi233 已提交
459
| 错误码ID | 错误信息                            |
W
wanghang 已提交
460
| -------- | --------------------------------------|
Z
zhaogan 已提交
461
| 17700001 | The specified bundleName is not found. |
462
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
463
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
464 465 466 467

**示例:**

```ts
J
junyi233 已提交
468
// 额外获取ApplicationInfo和SignatureInfo
L
Lotol 已提交
469
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
470
import hilog from '@ohos.hilog';
W
wanghang 已提交
471
let bundleName = 'com.example.myapplication';
J
junyi233 已提交
472
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
W
wanghang 已提交
473 474 475 476
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => {
L
longwei 已提交
477
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
478
    }).catch(err => {
L
longwei 已提交
479
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
480
    });
481
} catch (err) {
L
longwei 已提交
482
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
483 484 485 486
}
```

```ts
L
Lotol 已提交
487
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
488
import hilog from '@ohos.hilog';
W
wanghang 已提交
489 490 491 492 493
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => {
L
longwei 已提交
494
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
495
    }).catch(err => {
L
longwei 已提交
496
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
497
    });
498
} catch (err) {
L
longwei 已提交
499
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
500 501 502 503 504 505 506 507 508 509
}

```

### bundleManager.getApplicationInfo

getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void;

以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用callback形式返回结果。

G
geng-wenguang 已提交
510 511
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
512 513 514 515 516 517 518 519
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
520
| 参数名    | 类型   | 必填 | 说明                       |
W
wanghang 已提交
521
| ---------- | ------ | ---- | ---------------------------- |
522
| bundleName | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
523 524 525
| appFlags   | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。    |
| userId     | number | 是   | 表示用户ID。  |
| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 |
W
wanghang 已提交
526 527 528

**错误码:**

Z
zengyawen 已提交
529
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
530

J
junyi233 已提交
531
| 错误码ID | 错误信息                             |
W
wanghang 已提交
532
| -------- | --------------------------------------|
Z
zhaogan 已提交
533
| 17700001 | The specified bundleName is not found. |
534
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
535
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
536

Z
zhaogan 已提交
537
**示例:**
W
wanghang 已提交
538 539

```ts
L
Lotol 已提交
540
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
541
import hilog from '@ohos.hilog';
W
wanghang 已提交
542 543 544 545 546 547 548
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
549
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
550
        } else {
L
longwei 已提交
551
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
552 553 554
        }
    });
} catch (err) {
L
longwei 已提交
555
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
556 557 558 559 560 561 562 563 564
}
```

### bundleManager.getApplicationInfo

getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void;

以异步方法根据给定的bundleName和appFlags获取ApplicationInfo,使用callback形式返回结果。

G
geng-wenguang 已提交
565 566
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
567 568 569 570 571 572 573 574
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
575
| 参数名    | 类型   | 必填 | 说明                       |
W
wanghang 已提交
576
| ---------- | ------ | ---- | ---------------------------- |
577
| bundleName | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
578 579
| appFlags   | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。    |
| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的ApplicationInfo;否则为错误对象。 |
W
wanghang 已提交
580 581 582

**错误码:**

Z
zengyawen 已提交
583
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
584

J
junyi233 已提交
585
| 错误码ID | 错误信息                             |
W
wanghang 已提交
586
| -------- | --------------------------------------|
Z
zhaogan 已提交
587
| 17700001 | The specified bundleName is not found. |
588
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
589
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
590 591 592 593

**示例:**

```ts
L
Lotol 已提交
594
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
595
import hilog from '@ohos.hilog';
W
wanghang 已提交
596
let bundleName = 'com.example.myapplication';
Z
zhaogan 已提交
597
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
W
wanghang 已提交
598 599 600 601

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => {
        if (err) {
L
longwei 已提交
602
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
603
        } else {
L
longwei 已提交
604
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
605 606 607
        }
    });
} catch (err) {
L
longwei 已提交
608
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
609 610 611 612 613 614 615 616 617
}
```

### bundleManager.getApplicationInfo

getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId?: number): Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>;

以异步方法根据给定的bundleName、appFlags和userId获取ApplicationInfo,使用Promise形式返回结果。

G
geng-wenguang 已提交
618 619
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
620 621 622 623 624 625 626 627
**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
628
| 参数名    | 类型   | 必填 | 说明                       |
W
wanghang 已提交
629
| ---------- | ------ | ---- | ---------------------------- |
630
| bundleName | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
631 632
| appFlags   | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。    |
| userId     | number | 否   | 表示用户ID。 |
W
wanghang 已提交
633 634 635 636 637

**返回值:**

| 类型                                                         | 说明                             |
| ------------------------------------------------------------ | -------------------------------- |
Z
zhaogan 已提交
638
| Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Promise对象,返回ApplicationInfo。 |
W
wanghang 已提交
639 640 641

**错误码:**

Z
zengyawen 已提交
642
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
643

J
junyi233 已提交
644
| 错误码ID | 错误信息                             |
W
wanghang 已提交
645
| -------- | ------------------------------------- |
Z
zhaogan 已提交
646
| 17700001 | The specified bundleName is not found. |
647
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
648
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
649 650 651 652

**示例:**

```ts
L
Lotol 已提交
653
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
654
import hilog from '@ohos.hilog';
W
wanghang 已提交
655 656 657 658 659 660
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
let userId = 100;

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => {
L
longwei 已提交
661
        hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data));
662
    }).catch(err => {
L
longwei 已提交
663
        hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
664
    });
665
} catch (err) {
L
longwei 已提交
666
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
667 668 669 670 671 672 673
}
```

### bundleManager.getAllBundleInfo

getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void;

W
wtt1995 已提交
674
以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。
W
wanghang 已提交
675 676 677 678 679 680 681 682 683

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
684
| 参数名     | 类型   | 必填 | 说明                                             |
W
wanghang 已提交
685
| ----------- | ------ | ---- | -------------------------------------------------- |
Z
zhaogan 已提交
686 687 688
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。                    |
| userId      | number | 是   | 表示用户ID。                      |
| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 |
W
wanghang 已提交
689 690 691

**错误码:**

Z
zengyawen 已提交
692
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
693

J
junyi233 已提交
694
| 错误码ID | 错误信息                         |
W
wanghang 已提交
695
| -------- | --------------------------------- |
696
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
697 698 699 700

**示例:**

```ts
L
Lotol 已提交
701
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
702
import hilog from '@ohos.hilog';
W
wanghang 已提交
703 704 705 706 707 708
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;

try {
    bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
709
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
710
        } else {
L
longwei 已提交
711
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
712 713 714
        }
    });
} catch (err) {
L
longwei 已提交
715
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
716 717 718 719 720 721 722
}
```

### bundleManager.getAllBundleInfo

getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void;

W
wtt1995 已提交
723
以异步方法根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback形式返回结果。
W
wanghang 已提交
724 725 726 727 728 729 730 731 732

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
733
| 参数名     | 类型   | 必填 | 说明                                             |
W
wanghang 已提交
734
| ----------- | ------ | ---- | -------------------------------------------------- |
Z
zhaogan 已提交
735 736
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。   |
| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<BundleInfo>;否则为错误对象。 |
W
wanghang 已提交
737 738 739

**错误码:**

Z
zengyawen 已提交
740
错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
741

742 743 744 745
| 错误码ID | 错误信息                         |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |

W
wanghang 已提交
746 747 748
**示例:**

```ts
L
Lotol 已提交
749
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
750
import hilog from '@ohos.hilog';
W
wanghang 已提交
751 752 753 754 755
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags, (err, data) => {
        if (err) {
L
longwei 已提交
756
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
757
        } else {
L
longwei 已提交
758
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
759 760 761
        }
    });
} catch (err) {
L
longwei 已提交
762
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
763 764 765 766 767 768 769
}
```

### bundleManager.getAllBundleInfo

getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>;

W
wtt1995 已提交
770
以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise形式返回结果。
W
wanghang 已提交
771 772 773 774 775 776 777 778 779

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
780
| 参数名     | 类型   | 必填 | 说明                                             |
W
wanghang 已提交
781
| ----------- | ------ | ---- | -------------------------------------------------- |
Z
zhaogan 已提交
782 783
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。                   |
| userId      | number | 否   | 表示用户ID。                         |
W
wanghang 已提交
784 785 786 787 788

**返回值:**

| 类型                                                         | 说明                                |
| ------------------------------------------------------------ | ----------------------------------- |
Z
zhaogan 已提交
789
| Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Promise对象,返回Array\<BundleInfo>。 |
W
wanghang 已提交
790 791 792

**错误码:**

Z
zengyawen 已提交
793
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
794

J
junyi233 已提交
795
| 错误码ID | 错误信息                         |
W
wanghang 已提交
796
| -------- | ---------------------------------- |
797
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
798 799 800 801

**示例:**

```ts
L
Lotol 已提交
802
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
803
import hilog from '@ohos.hilog';
W
wanghang 已提交
804 805 806 807
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags).then((data) => {
L
longwei 已提交
808
        hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
809
    }).catch(err => {
L
longwei 已提交
810
        hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
811
    });
812
} catch (err) {
L
longwei 已提交
813
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
814 815 816 817 818 819 820
}
```

### bundleManager.getAllApplicationInfo

getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void;

W
wtt1995 已提交
821
以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。
W
wanghang 已提交
822 823 824 825 826 827 828 829 830

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
831
| 参数名  | 类型   | 必填 | 说明                                                      |
W
wanghang 已提交
832
| -------- | ------ | ---- | ----------------------------------------------------------- |
Z
zhaogan 已提交
833 834 835
| appFlags | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。                       |
| userId   | number | 是   | 表示用户ID。         |
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 |
W
wanghang 已提交
836 837 838

**错误码:**

Z
zengyawen 已提交
839
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
840

J
junyi233 已提交
841
| 错误码ID | 错误信息                         |
W
wanghang 已提交
842
| -------- | ---------------------------------- |
843
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
844 845 846 847

**示例:**

```ts
L
Lotol 已提交
848
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
849
import hilog from '@ohos.hilog';
W
wanghang 已提交
850 851 852 853 854 855
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
856
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
857
        } else {
L
longwei 已提交
858
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
859 860 861
        }
    });
} catch (err) {
L
longwei 已提交
862
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
863 864 865 866 867 868 869
}
```

### bundleManager.getAllApplicationInfo

getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void;

W
wtt1995 已提交
870
以异步方法根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback形式返回结果。
W
wanghang 已提交
871 872 873 874 875 876 877 878 879

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
880
| 参数名  | 类型   | 必填 | 说明                                                      |
W
wanghang 已提交
881
| -------- | ------ | ---- | ----------------------------------------------------------- |
Z
zhaogan 已提交
882 883
| appFlags | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。                       |
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<ApplicationInfo>;否则为错误对象。 |
W
wanghang 已提交
884 885 886

**错误码:**

Z
zengyawen 已提交
887
错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
888

889 890 891 892
| 错误码ID | 错误信息                         |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |

W
wanghang 已提交
893 894 895
**示例:**

```ts
L
Lotol 已提交
896
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
897
import hilog from '@ohos.hilog';
W
wanghang 已提交
898 899 900 901 902
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags, (err, data) => {
        if (err) {
L
longwei 已提交
903
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
904
        } else {
L
longwei 已提交
905
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
906 907 908
        }
    });
} catch (err) {
L
longwei 已提交
909
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
910 911 912 913 914 915 916
}
```

### bundleManager.getAllApplicationInfo

getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>;

W
wtt1995 已提交
917
以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise形式返回结果。
W
wanghang 已提交
918 919 920 921 922 923 924 925 926

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
927
| 参数名  | 类型   | 必填 | 说明                                                      |
W
wanghang 已提交
928
| -------- | ------ | ---- | ---------------------------------------------------------- |
Z
zhaogan 已提交
929 930
| appFlags | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。                       |
| userId   | number | 否   | 表示用户ID。                                  |
W
wanghang 已提交
931 932 933 934 935

**返回值:**

| 类型                                                         | 说明                                     |
| ------------------------------------------------------------ | ---------------------------------------- |
Z
zhaogan 已提交
936
| Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Promise对象,返回Array\<ApplicationInfo>。 |
W
wanghang 已提交
937 938 939

**错误码:**

Z
zengyawen 已提交
940
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
941

J
junyi233 已提交
942
| 错误码ID | 错误信息                         |
W
wanghang 已提交
943
| -------- | ---------------------------------- |
944
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
945 946 947 948

**示例:**

```ts
L
Lotol 已提交
949
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
950
import hilog from '@ohos.hilog';
W
wanghang 已提交
951 952 953 954
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags).then((data) => {
L
longwei 已提交
955
        hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data));
956
    }).catch(err => {
L
longwei 已提交
957
        hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
958
    });
959
} catch (err) {
L
longwei 已提交
960
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
}

```

### bundleManager.queryAbilityInfo

queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: number, callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void;

以异步方法根据给定的want、abilityFlags和userId获取多个AbilityInfo,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
979
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
980
| ------------ | ------ | ---- | ------------------------------------------------------- |
981
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
982 983 984
| abilityFlags | [number](#abilityflag) | 是   | 指定返回的AbilityInfo所包含的信息。                       |
| userId       | number | 是   | 表示用户ID。                               |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
985 986 987

**错误码:**

Z
zengyawen 已提交
988
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
989

J
junyi233 已提交
990
| 错误码ID | 错误信息                             |
W
wanghang 已提交
991
| -------- | -------------------------------------- |
Z
zhaogan 已提交
992 993 994 995 996
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified ability is not found.    |
| 17700004 | The specified userId is invalid.       |
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
997 998 999 1000

**示例:**

```ts
L
Lotol 已提交
1001
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1002
import hilog from '@ohos.hilog';
W
wanghang 已提交
1003 1004 1005 1006
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1007
    abilityName : "EntryAbility"
W
wanghang 已提交
1008 1009 1010 1011 1012
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
1013
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1014
        } else {
L
longwei 已提交
1015
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1016 1017 1018
        }
    });
} catch (err) {
L
longwei 已提交
1019
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
}
```

### bundleManager.queryAbilityInfo

queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void;

以异步方法根据给定的want和abilityFlags获取一个或多个AbilityInfo,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1037
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
1038
| ------------ | ------ | ---- | -------------------------------------------------------|
1039
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
1040 1041
| abilityFlags | [number](#abilityflag) | 是   | 指定返回的AbilityInfo所包含的信息。       |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
1042 1043 1044

**错误码:**

Z
zengyawen 已提交
1045
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1046

J
junyi233 已提交
1047
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1048
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1049 1050
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified ability is not found.    |
1051
| 17700004 | The specified userId is invalid.       |
Z
zhaogan 已提交
1052 1053
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
1054 1055 1056 1057

**示例:**

```ts
L
Lotol 已提交
1058
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1059
import hilog from '@ohos.hilog';
W
wanghang 已提交
1060 1061 1062
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1063
    abilityName : "EntryAbility"
W
wanghang 已提交
1064 1065 1066 1067 1068
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => {
        if (err) {
L
longwei 已提交
1069
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1070
        } else {
L
longwei 已提交
1071
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1072 1073 1074
        }
    });
} catch (err) {
L
longwei 已提交
1075
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
}
```

### bundleManager.queryAbilityInfo

queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>;

以异步方法根据给定的want、abilityFlags和userId获取一个或多个AbilityInfo,使用Promise形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1093
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
1094
| ------------ | ------ | ---- | ------------------------------------------------------- |
1095
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
1096 1097
| abilityFlags | [number](#abilityflag) | 是   | 表示指定返回的AbilityInfo所包含的信息。 |
| userId       | number | 否   | 表示用户ID。                               |
W
wanghang 已提交
1098 1099 1100 1101 1102

**返回值:**

| 类型                                                         | 说明                                 |
| ------------------------------------------------------------ | ------------------------------------ |
Z
zhaogan 已提交
1103
| Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Promise对象,返回Array\<AbilityInfo>。 |
W
wanghang 已提交
1104 1105 1106

**错误码:**

Z
zengyawen 已提交
1107
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1108

J
junyi233 已提交
1109
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1110
| -------- | ------------------------------------- |
Z
zhaogan 已提交
1111
| 17700001 | The specified bundleName is not found. |
X
xsz233 已提交
1112
| 17700003 | The specified ability is not found.    |
Z
zhaogan 已提交
1113 1114 1115
| 17700004 | The specified userId is invalid.       |
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
1116 1117 1118 1119

**示例:**

```ts
L
Lotol 已提交
1120
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1121
import hilog from '@ohos.hilog';
W
wanghang 已提交
1122 1123 1124 1125
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1126
    abilityName : "EntryAbility"
W
wanghang 已提交
1127 1128 1129 1130
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => {
L
longwei 已提交
1131
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1132
    }).catch(err => {
L
longwei 已提交
1133
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1134
    });
1135
} catch (err) {
L
longwei 已提交
1136
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1137 1138 1139 1140
}
```

```ts
L
Lotol 已提交
1141
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1142
import hilog from '@ohos.hilog';
W
wanghang 已提交
1143 1144 1145
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1146
    abilityName : "EntryAbility"
W
wanghang 已提交
1147 1148 1149 1150
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => {
L
longwei 已提交
1151
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1152
    }).catch(err => {
L
longwei 已提交
1153
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1154
    })
1155
} catch (err) {
L
longwei 已提交
1156
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
}
```

### bundleManager.queryExtensionAbilityInfo

queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId: number, callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void;

以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1174
| 参数名                | 类型                                                         | 必填 | 说明                                                         |
W
wanghang 已提交
1175
| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1176 1177 1178 1179
| want                  | Want                                                         | 是   | 表示包含要查询的应用Bundle名称的Want。                       |
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype)                | 是   | 标识extensionAbility的类型。                                 |
| extensionAbilityFlags | [number](#extensionabilityflag)                              | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。    |
| userId                | number                                                       | 是   | 表示用户ID。                                                 |
Z
zhaogan 已提交
1180
| callback              | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是   | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
1181 1182 1183

**错误码:**

Z
zengyawen 已提交
1184
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1185

J
junyi233 已提交
1186 1187
| 错误码ID | 错误信息                                    |
| -------- | ------------------------------------------- |
Z
zhaogan 已提交
1188 1189 1190 1191
| 17700001 | The specified bundleName is not found.       |
| 17700003 | The specified extensionAbility is not found. |
| 17700004 | The specified userId is invalid.             |
| 17700026 | The specified bundle is disabled.            |
W
wanghang 已提交
1192 1193 1194 1195

**示例:**

```ts
L
Lotol 已提交
1196
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1197
import hilog from '@ohos.hilog';
W
wanghang 已提交
1198 1199 1200 1201 1202
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1203
    abilityName : "EntryAbility"
W
wanghang 已提交
1204 1205 1206 1207 1208
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
1209
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1210
        } else {
L
longwei 已提交
1211
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1212 1213 1214
        }
    });
} catch (err) {
L
longwei 已提交
1215
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232
}
```

### bundleManager.queryExtensionAbilityInfo

queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void;

以异步方法根据给定的want、extensionAbilityType和extensionAbilityFlags获取一个或多个ExtensionAbilityInfo,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1233
| 参数名                | 类型                                                         | 必填 | 说明                                                         |
W
wanghang 已提交
1234
| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1235 1236 1237
| want                  | Want                                                         | 是   | 表示包含要查询的应用Bundle名称的Want。                       |
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype)                | 是   | 标识extensionAbility的类型。                                 |
| extensionAbilityFlags | [number](#extensionabilityflag)                              | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。    |
Z
zhaogan 已提交
1238
| callback              | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是   | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
1239 1240 1241

**错误码:**

Z
zengyawen 已提交
1242
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1243

J
junyi233 已提交
1244 1245
| 错误码ID | 错误信息                                     |
| -------- | -------------------------------------------- |
Z
zhaogan 已提交
1246 1247
| 17700001 | The specified bundleName is not found.       |
| 17700003 | The specified extensionAbility is not found. |
1248
| 17700004 | The specified userId is invalid.       |
Z
zhaogan 已提交
1249
| 17700026 | The specified bundle is disabled.            |
W
wanghang 已提交
1250 1251 1252 1253

**示例:**

```ts
L
Lotol 已提交
1254
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1255
import hilog from '@ohos.hilog';
W
wanghang 已提交
1256 1257 1258 1259
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1260
    abilityName : "EntryAbility"
W
wanghang 已提交
1261 1262 1263 1264 1265
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => {
        if (err) {
L
longwei 已提交
1266
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1267
        } else {
L
longwei 已提交
1268
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1269 1270 1271
        }
    });
} catch (err) {
L
longwei 已提交
1272
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
}
```

### bundleManager.queryExtensionAbilityInfo

queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>;

以异步方法根据给定的want、extensionAbilityType、extensionAbilityFlags和userId获取ExtensionAbilityInfo,使用Promise形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

1290 1291 1292
| 参数名                | 类型                                          | 必填 | 说明                                                      |
| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- |
| want                  | Want                                          | 是   | 表示包含要查询的应用Bundle名称的Want。                    |
Z
zhaogan 已提交
1293 1294 1295
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype) | 是   | 标识extensionAbility的类型。                              |
| extensionAbilityFlags | [number](#extensionabilityflag)               | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 |
| userId                | number                                        | 否   | 表示用户ID。                                              |
W
wanghang 已提交
1296 1297 1298 1299 1300

**返回值:**

| 类型                                                         | 说明                                          |
| ------------------------------------------------------------ | --------------------------------------------- |
Z
zhaogan 已提交
1301
| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Promise对象,返回Array\<ExtensionAbilityInfo>。 |
W
wanghang 已提交
1302 1303 1304

**错误码:**

Z
zengyawen 已提交
1305
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1306

J
junyi233 已提交
1307
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1308
| -------- | --------------------------------------|
Z
zhaogan 已提交
1309 1310 1311 1312
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified extensionAbility is not found.    |
| 17700004 | The specified userId is invalid.       |
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
1313 1314 1315 1316

**示例:**

```ts
L
Lotol 已提交
1317
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1318
import hilog from '@ohos.hilog';
W
wanghang 已提交
1319 1320 1321 1322 1323 1324

let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1325
    abilityName : "EntryAbility"
W
wanghang 已提交
1326 1327 1328 1329
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => {
L
longwei 已提交
1330
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1331
    }).catch(err => {
L
longwei 已提交
1332
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1333
    });
1334
} catch (err) {
L
longwei 已提交
1335
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1336 1337 1338 1339
}
```

```ts
L
Lotol 已提交
1340
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1341
import hilog from '@ohos.hilog';
W
wanghang 已提交
1342 1343 1344 1345
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1346
    abilityName : "EntryAbility"
W
wanghang 已提交
1347 1348 1349 1350
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => {
L
longwei 已提交
1351
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1352
    }).catch(err => {
L
longwei 已提交
1353
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1354
    })
1355
} catch (err) {
L
longwei 已提交
1356
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1357 1358 1359 1360 1361 1362 1363
}
```

### bundleManager.getBundleNameByUid

getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void;

W
wtt1995 已提交
1364
以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。
W
wanghang 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1374
| 参数名   | 类型                   | 必填 | 说明                                                         |
W
wanghang 已提交
1375
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1376 1377
| uid      | number                 | 是   | 表示应用程序的UID。                                            |
| callback | AsyncCallback\<string> | 是   | 回调函数,当获取成功时,err为null,data为获取到的BundleName;否则为错误对象。 |
W
wanghang 已提交
1378 1379 1380

**错误码:**

Z
zengyawen 已提交
1381
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1382

J
junyi233 已提交
1383
| 错误码ID | 错误信息            |
W
wanghang 已提交
1384
| -------- | --------------------- |
Z
zhaogan 已提交
1385
| 17700021 | The uid is not found. |
W
wanghang 已提交
1386 1387 1388 1389

**示例:**

```ts
L
Lotol 已提交
1390
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1391
import hilog from '@ohos.hilog';
W
wanghang 已提交
1392 1393 1394 1395
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid, (err, data) => {
        if (err) {
L
longwei 已提交
1396
            hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message);
W
wanghang 已提交
1397
        } else {
L
longwei 已提交
1398
            hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1399 1400 1401
        }
    });
} catch (err) {
L
longwei 已提交
1402
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message);
W
wanghang 已提交
1403 1404 1405 1406 1407 1408 1409
}
```

### bundleManager.getBundleNameByUid

getBundleNameByUid(uid: number): Promise\<string>;

W
wtt1995 已提交
1410
以异步方法根据给定的uid获取对应的bundleName,使用Promise形式返回结果。
W
wanghang 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1420
| 参数名 | 类型   | 必填 | 说明                |
W
wanghang 已提交
1421
| ---- | ------ | ---- | ------------------ |
Z
zhaogan 已提交
1422
| uid  | number | 是   | 表示应用程序的UID。 |
W
wanghang 已提交
1423 1424 1425 1426 1427

**返回值:**

| 类型             | 说明                        |
| ---------------- | --------------------------- |
Z
zhaogan 已提交
1428
| Promise\<string> | Promise对象,返回bundleName。 |
W
wanghang 已提交
1429 1430 1431

**错误码:**

Z
zengyawen 已提交
1432
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1433

J
junyi233 已提交
1434
| 错误码ID | 错误信息            |
W
wanghang 已提交
1435
| -------- | ---------------------|
Z
zhaogan 已提交
1436
| 17700021 | The uid is not found. |
W
wanghang 已提交
1437 1438 1439 1440

**示例:**

```ts
L
Lotol 已提交
1441
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1442
import hilog from '@ohos.hilog';
W
wanghang 已提交
1443 1444 1445
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid).then((data) => {
L
longwei 已提交
1446
        hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data));
1447
    }).catch(err => {
L
longwei 已提交
1448
        hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1449
    });
1450
} catch (err) {
L
longwei 已提交
1451
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
}
```

### bundleManager.getBundleArchiveInfo

getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void;

以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1469
| 参数名       | 类型   | 必填 | 说明                                                         |
W
wanghang 已提交
1470
| ----------- | ------ | ---- | ----------------------------------------------------------- |
Z
zhaogan 已提交
1471 1472 1473
| hapFilePath | string | 是   | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。       |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | 是 | 回调函数,当获取成功时,err为null,data为获取到的BundleInfo;否则为错误对象。 |
W
wanghang 已提交
1474 1475 1476

**错误码:**

Z
zengyawen 已提交
1477
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1478

J
junyi233 已提交
1479
| 错误码ID | 错误信息                  |
W
wanghang 已提交
1480
| -------- | --------------------------- |
Z
zhaogan 已提交
1481
| 17700022 | The hapFilePath is invalid. |
W
wanghang 已提交
1482 1483 1484 1485

**示例:**

```ts
L
Lotol 已提交
1486
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1487
import hilog from '@ohos.hilog';
W
wanghang 已提交
1488 1489 1490 1491 1492 1493
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
        if (err) {
L
longwei 已提交
1494
            hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1495
        } else {
L
longwei 已提交
1496
            hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1497 1498 1499
        }
    });
} catch (err) {
L
longwei 已提交
1500
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
}
```

### bundleManager.getBundleArchiveInfo

getBundleArchiveInfo(hapFilePath: string,  bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>;

以异步方法根据给定的hapFilePath和bundleFlags获取BundleInfo,使用Promise形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1518
| 参数名       | 类型   | 必填 | 说明                                                         |
W
wanghang 已提交
1519
| ----------- | ------ | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1520 1521
| hapFilePath | string | 是   | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。       |
W
wanghang 已提交
1522 1523 1524 1525 1526

**返回值:**

| 类型                                                        | 说明                        |
| ----------------------------------------------------------- | --------------------------- |
Z
zhaogan 已提交
1527
| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise对象,返回BundleInfo。 |
W
wanghang 已提交
1528 1529 1530

**错误码:**

Z
zengyawen 已提交
1531
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1532

J
junyi233 已提交
1533
| 错误码ID | 错误信息                   |
W
wanghang 已提交
1534
| -------- | -------------------------- |
Z
zhaogan 已提交
1535
| 17700022 | The hapFilePath is invalid. |
W
wanghang 已提交
1536 1537 1538 1539

**示例:**

```ts
L
Lotol 已提交
1540
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1541
import hilog from '@ohos.hilog';
W
wanghang 已提交
1542 1543 1544 1545 1546
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => {
L
longwei 已提交
1547
        hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data));
1548
    }).catch(err => {
L
longwei 已提交
1549
        hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1550
    });
1551
} catch (err) {
L
longwei 已提交
1552
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1553 1554 1555 1556 1557 1558 1559
}
```

### bundleManager.cleanBundleCacheFiles

cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\<void>): void;

W
wtt1995 已提交
1560
以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。
W
wanghang 已提交
1561 1562 1563 1564 1565 1566 1567 1568 1569

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.REMOVE_CACHE_FILES

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1570
| 参数名     | 类型                 | 必填 | 说明                                                         |
W
wanghang 已提交
1571
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1572 1573
| bundleName | string               | 是   | 表示要清理其缓存数据的应用程序的bundleName。                   |
| callback   | AsyncCallback\<void> | 是   | 回调函数,当清理应用缓存目录数据成功,err为null,否则为错误对象。 |
W
wanghang 已提交
1574 1575 1576

**错误码:**

Z
zengyawen 已提交
1577
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1578

J
junyi233 已提交
1579
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
1580
| -------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1581
| 17700001 | The specified bundleName is not found.                        |
1582
| 17700030 | The specified bundle does not support clearing of cache files. |
W
wanghang 已提交
1583 1584 1585 1586

**示例:**

```ts
L
Lotol 已提交
1587
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1588
import hilog from '@ohos.hilog';
W
wanghang 已提交
1589 1590 1591 1592 1593
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.cleanBundleCacheFiles(bundleName, err => {
        if (err) {
L
longwei 已提交
1594
            hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1595
        } else {
G
geng-wenguang 已提交
1596
            hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
W
wanghang 已提交
1597 1598 1599
        }
    });
} catch (err) {
L
longwei 已提交
1600
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1601 1602 1603 1604 1605 1606 1607
}
```

### bundleManager.cleanBundleCacheFiles

cleanBundleCacheFiles(bundleName: string): Promise\<void>;

W
wtt1995 已提交
1608
以异步方法根据给定的bundleName清理BundleCache,使用Promise形式返回结果。
W
wanghang 已提交
1609 1610 1611 1612 1613 1614 1615 1616 1617

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.REMOVE_CACHE_FILES

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1618 1619
| 参数名     | 类型   | 必填 | 说明                                       |
| ---------- | ------ | ---- | ------------------------------------------ |
Z
zhaogan 已提交
1620
| bundleName | string | 是   | 表示要清理其缓存数据的应用程序的bundleName。 |
W
wanghang 已提交
1621 1622 1623 1624 1625

**返回值:**

| 类型           | 说明                                                         |
| -------------- | ------------------------------------------------------------ |
W
wtt1995 已提交
1626
| Promise\<void> | 无返回结果的Promise对象。当清理应用缓存目录数据失败会抛出错误对象。 |
W
wanghang 已提交
1627 1628 1629

**错误码:**

Z
zengyawen 已提交
1630
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1631

J
junyi233 已提交
1632 1633
| 错误码ID | 错误信息                                                   |
| -------- | ---------------------------------------------------------- |
Z
zhaogan 已提交
1634
| 17700001 | The specified bundleName is not found.                      |
J
junyi233 已提交
1635
| 17700030 | The specified bundle does not support clearing of cache files. |
W
wanghang 已提交
1636 1637 1638 1639

**示例:**

```ts
L
Lotol 已提交
1640
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1641
import hilog from '@ohos.hilog';
W
wanghang 已提交
1642 1643 1644
let bundleName = "com.ohos.myapplication";

try {
W
wtt1995 已提交
1645
    bundleManager.cleanBundleCacheFiles(bundleName).then(() => {
G
geng-wenguang 已提交
1646
        hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
W
wtt1995 已提交
1647
    }).catch(err => {
L
longwei 已提交
1648
        hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1649 1650
    });
} catch (err) {
L
longwei 已提交
1651
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1652 1653 1654 1655 1656 1657 1658
}
```

### bundleManager.setApplicationEnabled

setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\<void>): void;

W
wtt1995 已提交
1659
设置指定应用的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1660 1661 1662 1663 1664 1665 1666 1667 1668

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1669
| 参数名      | 类型    | 必填 | 说明                                  |
W
wanghang 已提交
1670
| ---------- | ------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1671 1672
| bundleName | string  | 是   | 指定应用的bundleName。                |
| isEnabled  | boolean | 是   | 值为true表示使能,值为false表示禁用。 |
W
wtt1995 已提交
1673
| callback | AsyncCallback\<void> | 是 | 回调函数,当设置应用禁用或使能状态成功时,err为null,否则为错误对象。 |
W
wanghang 已提交
1674 1675 1676

**错误码:**

Z
zengyawen 已提交
1677
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1678

J
junyi233 已提交
1679
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1680
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1681
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1682 1683 1684 1685

**示例:**

```ts
L
Lotol 已提交
1686
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1687
import hilog from '@ohos.hilog';
W
wanghang 已提交
1688 1689 1690 1691 1692
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.setApplicationEnabled(bundleName, false, err => {
        if (err) {
L
longwei 已提交
1693
            hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1694
        } else {
G
geng-wenguang 已提交
1695
            hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.');
W
wanghang 已提交
1696 1697 1698
        }
    });
} catch (err) {
L
longwei 已提交
1699
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1700 1701 1702 1703 1704 1705 1706
}
```

### bundleManager.setApplicationEnabled

setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\<void>;

W
wtt1995 已提交
1707
设置指定应用的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1708 1709 1710 1711 1712 1713 1714 1715 1716

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1717
| 参数名      | 类型    | 必填 | 说明                                  |
W
wanghang 已提交
1718
| ---------- | ------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1719 1720
| bundleName | string  | 是   | 表示应用程序的bundleName。            |
| isEnabled  | boolean | 是   | 值为true表示使能,值为false表示禁用。 |
W
wanghang 已提交
1721 1722 1723 1724 1725

**返回值:**

| 类型           | 说明                                 |
| -------------- | ------------------------------------ |
Z
zhaogan 已提交
1726
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
W
wanghang 已提交
1727 1728 1729

**错误码:**

Z
zengyawen 已提交
1730
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1731

J
junyi233 已提交
1732
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1733
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1734
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1735 1736 1737 1738

**示例:**

```ts
L
Lotol 已提交
1739
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1740
import hilog from '@ohos.hilog';
W
wanghang 已提交
1741 1742 1743
let bundleName = "com.ohos.myapplication";

try {
W
wtt1995 已提交
1744
    bundleManager.setApplicationEnabled(bundleName, false).then(() => {
G
geng-wenguang 已提交
1745
        hilog.info(0x0000, "testTag", "setApplicationEnabled successfully.");
W
wtt1995 已提交
1746
    }).catch(err => {
L
longwei 已提交
1747
        hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1748 1749
    });
} catch (err) {
L
longwei 已提交
1750
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1751 1752 1753 1754 1755 1756 1757
}
```

### bundleManager.setAbilityEnabled

setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean, callback: AsyncCallback\<void>): void;

W
wtt1995 已提交
1758
设置指定组件的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1759 1760 1761 1762 1763 1764 1765 1766 1767

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1768
| 参数名    | 类型        | 必填 | 说明                                  |
W
wanghang 已提交
1769
| -------- | ----------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1770 1771
| info     | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 需要被设置的组件。              |
| isEnabled| boolean     | 是   | 值为true表示使能,值为false表示禁用。 |
W
wtt1995 已提交
1772
| callback | AsyncCallback\<void> | 是 | 回调函数,当设置组件禁用或使能状态成功时,err为null,否则为错误对象。 |
W
wanghang 已提交
1773 1774 1775

**错误码:**

Z
zengyawen 已提交
1776
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1777

J
junyi233 已提交
1778
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1779
| -------- | ---------------------------------------|
Z
zhaogan 已提交
1780 1781
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityInfo is not found. |
W
wanghang 已提交
1782 1783 1784 1785

**示例:**

```ts
L
Lotol 已提交
1786
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1787
import hilog from '@ohos.hilog';
W
wanghang 已提交
1788 1789 1790 1791
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1792
    abilityName : "EntryAbility"
W
wanghang 已提交
1793
};
1794
let info;
W
wanghang 已提交
1795 1796 1797

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
L
longwei 已提交
1798
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
W
wanghang 已提交
1799 1800 1801 1802
        info = abilitiesInfo[0];

        bundleManager.setAbilityEnabled(info, false, err => {
            if (err) {
L
longwei 已提交
1803
                hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1804
            } else {
G
geng-wenguang 已提交
1805
                hilog.info(0x0001, "testTag", "setAbilityEnabled successfully.");
W
wanghang 已提交
1806 1807
            }
        });
1808
    }).catch(err => {
L
longwei 已提交
1809
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1810
    });
1811
} catch (err) {
L
longwei 已提交
1812
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1813 1814 1815 1816 1817 1818 1819
}
```

### bundleManager.setAbilityEnabled

setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): Promise\<void>;

W
wtt1995 已提交
1820
设置指定组件的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1821 1822 1823 1824 1825 1826 1827 1828 1829

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.CHANGE_ABILITY_ENABLED_STATE

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1830
| 参数名    | 类型        | 必填 | 说明                                  |
W
wanghang 已提交
1831
| -------- | ----------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1832 1833
| info     | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 需要被设置的组件。                   |
| isEnabled| boolean     | 是   | 值为true表示使能,值为false表示禁用。 |
W
wanghang 已提交
1834 1835 1836 1837 1838

**返回值:**

| 类型           | 说明                              |
| -------------- | --------------------------------- |
Z
zhaogan 已提交
1839
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
W
wanghang 已提交
1840 1841 1842

**错误码:**

Z
zengyawen 已提交
1843
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1844

J
junyi233 已提交
1845
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1846
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1847 1848
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityInfo is not found. |
W
wanghang 已提交
1849 1850 1851 1852

**示例:**

```ts
L
Lotol 已提交
1853
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1854
import hilog from '@ohos.hilog';
W
wanghang 已提交
1855 1856 1857 1858
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1859
    abilityName : "EntryAbility"
W
wanghang 已提交
1860
};
1861
let info;
W
wanghang 已提交
1862 1863 1864

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
L
longwei 已提交
1865
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
W
wanghang 已提交
1866 1867
        info = abilitiesInfo[0];

W
wtt1995 已提交
1868
        bundleManager.setAbilityEnabled(info, false).then(() => {
G
geng-wenguang 已提交
1869
            hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
W
wtt1995 已提交
1870
        }).catch(err => {
L
longwei 已提交
1871
            hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1872
        });
1873
    }).catch(err => {
L
longwei 已提交
1874
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1875
    });
1876
} catch (err) {
L
longwei 已提交
1877
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1878 1879 1880 1881 1882 1883 1884
}
```

### bundleManager.isApplicationEnabled

isApplicationEnabled(bundleName: string, callback: AsyncCallback\<boolean>): void;

W
wtt1995 已提交
1885
以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1886 1887 1888 1889 1890 1891 1892

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1893
| 参数名      | 类型   | 必填 | 说明                       |
W
wanghang 已提交
1894
| ---------- | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
1895 1896
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。 |
W
wanghang 已提交
1897 1898 1899

**错误码:**

Z
zengyawen 已提交
1900
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1901

J
junyi233 已提交
1902
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1903
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1904
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1905 1906 1907 1908

**示例:**

```ts
L
Lotol 已提交
1909
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1910
import hilog from '@ohos.hilog';
W
wanghang 已提交
1911 1912 1913 1914 1915
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName, (err, data) => {
        if (err) {
L
longwei 已提交
1916
            hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1917
        } else {
L
longwei 已提交
1918
            hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1919 1920 1921
        }
    });
} catch (err) {
L
longwei 已提交
1922
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1923 1924 1925 1926 1927 1928 1929
}
```

### bundleManager.isApplicationEnabled

isApplicationEnabled(bundleName: string): Promise\<boolean>;

W
wtt1995 已提交
1930
以异步的方法获取指定应用的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1931 1932 1933 1934 1935 1936 1937

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1938
| 参数名      | 类型   | 必填 | 说明                       |
W
wanghang 已提交
1939
| ---------- | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
1940
| bundleName | string | 是   | 表示应用程序的bundleName。  |
W
wanghang 已提交
1941 1942 1943 1944 1945 1946 1947 1948 1949

**返回值:**

| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise对象,返回true表示当前应用为使能状态,返回false表示当前应用为禁用状态。 |

**错误码:**

Z
zengyawen 已提交
1950
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1951

J
junyi233 已提交
1952
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1953
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1954
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1955 1956 1957 1958

**示例:**

```ts
L
Lotol 已提交
1959
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1960
import hilog from '@ohos.hilog';
W
wanghang 已提交
1961 1962 1963 1964
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName).then((data) => {
L
longwei 已提交
1965
        hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data));
1966
    }).catch(err => {
L
longwei 已提交
1967
        hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1968
    });
1969
} catch (err) {
L
longwei 已提交
1970
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1971 1972 1973 1974 1975 1976 1977
}
```

### bundleManager.isAbilityEnabled

isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), callback: AsyncCallback\<boolean>): void;

W
wtt1995 已提交
1978
以异步的方法获取指定组件的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1979 1980 1981 1982 1983 1984 1985

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
1986
| 参数名 | 类型        | 必填 | 说明                        |
W
wanghang 已提交
1987
| ---- | ----------- | ---- | --------------------------- |
Z
zhaogan 已提交
1988 1989
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 表示关于检查ability的信息。 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用组件为使能状态,返回false表示应用组件为禁用状态。 |
W
wanghang 已提交
1990 1991 1992

**错误码:**

Z
zengyawen 已提交
1993
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
1994

J
junyi233 已提交
1995
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1996
| -------- | --------------------------------------- |
Z
zhaogan 已提交
1997 1998
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityName is not found. |
W
wanghang 已提交
1999 2000 2001 2002

**示例:**

```ts
L
Lotol 已提交
2003
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2004
import hilog from '@ohos.hilog';
W
wanghang 已提交
2005 2006 2007 2008
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
2009
    abilityName : "EntryAbility"
W
wanghang 已提交
2010
};
2011
let info;
W
wanghang 已提交
2012 2013 2014

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
L
longwei 已提交
2015
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
W
wanghang 已提交
2016 2017 2018 2019
        info = abilitiesInfo[0];

        bundleManager.isAbilityEnabled(info, (err, data) => {
            if (err) {
L
longwei 已提交
2020
                hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message);
W
wanghang 已提交
2021
            } else {
L
longwei 已提交
2022
                hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2023 2024
            }
        });
2025
    }).catch(err => {
L
longwei 已提交
2026
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2027
    });
2028
} catch (err) {
L
longwei 已提交
2029
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2030 2031 2032 2033 2034 2035 2036
}
```

### bundleManager.isAbilityEnabled

isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Promise\<boolean>;

W
wtt1995 已提交
2037
以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
2038 2039 2040 2041 2042 2043 2044

**系统接口:** 此接口为系统接口。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
2045
| 参数名 | 类型        | 必填 | 说明                        |
W
wanghang 已提交
2046
| ---- | ----------- | ---- | --------------------------- |
Z
zhaogan 已提交
2047
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 表示关于检查ability的信息。 |
W
wanghang 已提交
2048 2049 2050 2051 2052 2053 2054 2055 2056

**返回值:**

| 类型              | 说明                                                         |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise对象,返回true表示当前应用组件为使能状态,返回false表示当前应用组件为禁用状态。 |

**错误码:**

Z
zengyawen 已提交
2057
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2058

J
junyi233 已提交
2059
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2060
| -------- | --------------------------------------- |
Z
zhaogan 已提交
2061 2062
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityName is not found. |
W
wanghang 已提交
2063 2064 2065 2066

**示例:**

```ts
L
Lotol 已提交
2067
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2068
import hilog from '@ohos.hilog';
W
wanghang 已提交
2069 2070 2071 2072
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
2073
    abilityName : "EntryAbility"
W
wanghang 已提交
2074
};
2075
let info;
W
wanghang 已提交
2076 2077 2078

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
L
longwei 已提交
2079
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
W
wanghang 已提交
2080 2081 2082
        info = abilitiesInfo[0];

        bundleManager.isAbilityEnabled(info).then((data) => {
L
longwei 已提交
2083
            hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2084
        }).catch(err => {
L
longwei 已提交
2085
            hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2086
        });
2087
    }).catch(err => {
L
longwei 已提交
2088
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2089
    });
2090
} catch (err) {
L
longwei 已提交
2091
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2092 2093 2094 2095 2096 2097 2098
}
```

### bundleManager.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\<Want>): void;

W
wtt1995 已提交
2099
以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。
W
wanghang 已提交
2100 2101 2102 2103 2104 2105 2106 2107 2108

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
2109
| 参数名     | 类型                 | 必填 | 说明                                                         |
W
wanghang 已提交
2110
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2111 2112 2113
| bundleName | string               | 是   | 表示应用程序的bundleName。                                     |
| userId     | number               | 是   | 表示用户ID。                                                   |
| callback   | AsyncCallback\<Want> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 |
W
wanghang 已提交
2114 2115 2116

**错误码:**

Z
zengyawen 已提交
2117
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2118

J
junyi233 已提交
2119
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2120
| -------- | --------------------------------------|
Z
zhaogan 已提交
2121
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2122
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2123
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2124 2125 2126 2127

**示例:**

```ts
L
Lotol 已提交
2128
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2129
import hilog from '@ohos.hilog';
W
wanghang 已提交
2130 2131 2132 2133 2134 2135
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => {
        if (err) {
L
longwei 已提交
2136
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2137
        } else {
L
longwei 已提交
2138
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2139 2140 2141
        }
    });
} catch (err) {
L
longwei 已提交
2142
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2143 2144 2145 2146 2147 2148 2149
}
```

### bundleManager.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void;

W
wtt1995 已提交
2150
以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。
W
wanghang 已提交
2151 2152 2153 2154 2155 2156 2157 2158 2159

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
2160
| 参数名     | 类型                 | 必填 | 说明                                                         |
W
wanghang 已提交
2161
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2162 2163
| bundleName | string               | 是   | 表示应用程序的bundleName。                                     |
| callback   | AsyncCallback\<Want> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 |
W
wanghang 已提交
2164 2165 2166

**错误码:**

Z
zengyawen 已提交
2167
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2168

J
junyi233 已提交
2169
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2170
| -------- | --------------------------------------|
Z
zhaogan 已提交
2171
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2172
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2173
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2174 2175 2176 2177

**示例:**

```ts
L
Lotol 已提交
2178
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2179
import hilog from '@ohos.hilog';
W
wanghang 已提交
2180 2181 2182 2183 2184
let bundleName = 'com.example.myapplication';

try {
    bundleManager.getLaunchWantForBundle(bundleName, (err, data) => {
        if (err) {
L
longwei 已提交
2185
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2186
        } else {
L
longwei 已提交
2187
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2188 2189 2190
        }
    });
} catch (err) {
L
longwei 已提交
2191
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2192 2193 2194 2195 2196 2197 2198
}
```

### bundleManager.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string, userId?: number): Promise\<Want>;

W
wtt1995 已提交
2199
以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise形式返回结果。
W
wanghang 已提交
2200 2201 2202 2203 2204 2205 2206 2207 2208

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

Z
zhaogan 已提交
2209 2210 2211 2212
| 参数名     | 类型   | 必填 | 说明                       |
| ---------- | ------ | ---- | ------------------------- |
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| userId     | number | 否   | 表示用户ID。               |
W
wanghang 已提交
2213 2214 2215 2216 2217

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
Z
zhaogan 已提交
2218
| Promise\<Want> | Promise对象,返回Want对象。 |
W
wanghang 已提交
2219 2220 2221

**错误码:**

Z
zengyawen 已提交
2222
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2223

J
junyi233 已提交
2224
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2225
| -------- | --------------------------------------|
Z
zhaogan 已提交
2226
| 17700001 | The specified bundleName is not found. |
2227
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2228
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2229 2230 2231 2232

**示例:**

```ts
L
Lotol 已提交
2233
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2234
import hilog from '@ohos.hilog';
W
wanghang 已提交
2235 2236 2237 2238 2239
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => {
L
longwei 已提交
2240
        hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data));
2241
    }).catch(err => {
L
longwei 已提交
2242
        hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2243
    });
2244
} catch (err) {
L
longwei 已提交
2245
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2246 2247 2248 2249 2250
}
```

### bundleManager.getProfileByAbility

J
junyi233 已提交
2251
getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void;
W
wanghang 已提交
2252 2253 2254 2255 2256 2257 2258

以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
2259
| 参数名       | 类型                          | 必填 | 说明                                                         |
W
wanghang 已提交
2260
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2261 2262 2263 2264
| moduleName   | string                        | 是   | 表示应用程序的moduleName。                                     |
| abilityName  | string                        | 是   | 表示应用程序的abilityName。                                    |
| metadataName | string                        | 是   | 表示应用程序的metadataName。                                  |
| callback     | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
W
wanghang 已提交
2265 2266 2267

**错误码:**

Z
zengyawen 已提交
2268
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2269

J
junyi233 已提交
2270
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2271
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2272 2273
| 17700002 | The specified moduleName is not existed.                      |
| 17700003 | The specified abilityName is not existed.                     |
2274
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2275 2276
| 17700026 | The specified bundle is disabled.                             |
| 17700029 | The specified ability is disabled.                            |
W
wanghang 已提交
2277 2278 2279 2280

**示例:**

```ts
L
Lotol 已提交
2281
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2282
import hilog from '@ohos.hilog';
W
wanghang 已提交
2283
let moduleName = 'entry';
2284
let abilityName = 'EntryAbility';
W
wanghang 已提交
2285 2286 2287 2288 2289
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
        if (err) {
L
longwei 已提交
2290
            hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2291
        } else {
L
longwei 已提交
2292
            hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2293 2294 2295
        }
    });
} catch (err) {
L
longwei 已提交
2296
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2297 2298 2299 2300 2301
}
```

### bundleManager.getProfileByAbility

J
junyi233 已提交
2302
getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string\>\>;
W
wanghang 已提交
2303 2304 2305 2306 2307 2308 2309

以异步方法根据给定的moduleName、abilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
2310
| 参数名       | 类型   | 必填 | 说明                       |
W
wanghang 已提交
2311
| ------------ | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
2312 2313 2314
| moduleName   | string | 是   | 表示应用程序的moduleName。   |
| abilityName  | string | 是   | 表示应用程序的abilityName。  |
| metadataName | string | 否   | 表示应用程序的metadataName。 |
W
wanghang 已提交
2315 2316 2317 2318 2319

**返回值:**

| 类型                    | 说明                            |
| ----------------------- | ------------------------------- |
Z
zhaogan 已提交
2320
| Promise<Array\<string>> | Promise对象,返回Array\<string>。 |
W
wanghang 已提交
2321 2322 2323

**错误码:**

Z
zengyawen 已提交
2324
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2325

J
junyi233 已提交
2326
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2327
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2328 2329
| 17700002 | The specified moduleName is not existed.                      |
| 17700003 | The specified abilityName is not existed.                     |
2330
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2331 2332
| 17700026 | The specified bundle is disabled.                             |
| 17700029 | The specified ability is disabled.                            |
W
wanghang 已提交
2333 2334 2335 2336

**示例:**

```ts
L
Lotol 已提交
2337
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2338
import hilog from '@ohos.hilog';
W
wanghang 已提交
2339
let moduleName = 'entry';
2340
let abilityName = 'EntryAbility';
W
wanghang 已提交
2341 2342 2343

try {
    bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
L
longwei 已提交
2344
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
2345
    }).catch(err => {
L
longwei 已提交
2346
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2347
    });
2348
} catch (err) {
L
longwei 已提交
2349
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2350
}
Z
zhaogan 已提交
2351
```
W
wanghang 已提交
2352

Z
zhaogan 已提交
2353
```ts
L
Lotol 已提交
2354
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2355
import hilog from '@ohos.hilog';
Z
zhaogan 已提交
2356
let moduleName = 'entry';
2357
let abilityName = 'EntryAbility';
Z
zhaogan 已提交
2358
let metadataName = 'com.example.myapplication.metadata';
W
wanghang 已提交
2359
try {
Z
zhaogan 已提交
2360
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
L
longwei 已提交
2361
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
2362
    }).catch(err => {
L
longwei 已提交
2363
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2364
    });
2365
} catch (err) {
L
longwei 已提交
2366
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2367 2368 2369 2370 2371
}
```

### bundleManager.getProfileByExtensionAbility

J
junyi233 已提交
2372
getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string\>\>): void;
W
wanghang 已提交
2373 2374 2375 2376 2377 2378 2379

以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用callback形式返回结果。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

2380
| 参数名                 | 类型                          | 必填 | 说明                                                         |
W
wanghang 已提交
2381
| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ |
J
junyi233 已提交
2382 2383 2384
| moduleName           | string                        | 是   | 表示应用程序的moduleName。                                   |
| extensionAbilityName | string                        | 是   | 表示应用程序的extensionAbilityName。                         |
| metadataName         | string                        | 是   | 表示应用程序的metadataName。                                 |
Z
zhaogan 已提交
2385
| callback             | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
W
wanghang 已提交
2386 2387 2388

**错误码:**

Z
zengyawen 已提交
2389
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2390

J
junyi233 已提交
2391
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2392
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2393
| 17700002 | The specified moduleName is not existed.                      |
J
junyi233 已提交
2394
| 17700003 | The specified extensionAbilityName not existed.            |
2395
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2396
| 17700026 | The specified bundle is disabled.                             |
W
wanghang 已提交
2397 2398 2399 2400

**示例:**

```ts
L
Lotol 已提交
2401
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2402
import hilog from '@ohos.hilog';
W
wanghang 已提交
2403 2404 2405 2406 2407 2408 2409
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => {
        if (err) {
L
longwei 已提交
2410
            hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
W
wanghang 已提交
2411
        } else {
L
longwei 已提交
2412
            hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2413 2414 2415
        }
    });
} catch (err) {
L
longwei 已提交
2416
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
W
wanghang 已提交
2417 2418 2419 2420 2421
}
```

### bundleManager.getProfileByExtensionAbility

J
junyi233 已提交
2422
getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string\>\>;
W
wanghang 已提交
2423 2424 2425 2426 2427 2428 2429

以异步方法根据给定的moduleName、extensionAbilityName和metadataName获取相应配置文件的json格式字符串,使用Promise形式返回结果。

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

2430
| 参数名                 | 类型   | 必填 | 说明                               |
J
junyi233 已提交
2431
| -------------------- | ------ | ---- | ---------------------------------- |
Z
zhaogan 已提交
2432 2433 2434
| moduleName           | string | 是   | 表示应用程序的moduleName。           |
| extensionAbilityName | string | 是   | 表示应用程序的extensionAbilityName。 |
| metadataName         | string | 否   | 表示应用程序的metadataName。         |
W
wanghang 已提交
2435 2436 2437 2438 2439

**返回值:**

| 类型                    | 说明                                |
| ----------------------- | ----------------------------------- |
Z
zhaogan 已提交
2440
| Promise<Array\<string>> | Promise对象,返回Array\<string>对象。 |
W
wanghang 已提交
2441 2442 2443

**错误码:**

Z
zengyawen 已提交
2444
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2445

J
junyi233 已提交
2446
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2447
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2448
| 17700002 | The specified moduleName is not existed.                      |
J
junyi233 已提交
2449
| 17700003 | The specified extensionAbilityName not existed.            |
2450
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2451
| 17700026 | The specified bundle is disabled.                             |
W
wanghang 已提交
2452 2453 2454 2455

**示例:**

```ts
L
Lotol 已提交
2456
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2457
import hilog from '@ohos.hilog';
W
wanghang 已提交
2458 2459 2460 2461 2462 2463
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
L
longwei 已提交
2464
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
2465
    }).catch(err => {
L
longwei 已提交
2466
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2467
    });
2468
} catch (err) {
L
longwei 已提交
2469
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2470 2471 2472 2473
}

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => {
L
longwei 已提交
2474
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
2475
    }).catch(err => {
L
longwei 已提交
2476
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2477
    });
2478
} catch (err) {
L
longwei 已提交
2479
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2480 2481 2482 2483 2484 2485 2486
}
```

### bundleManager.getPermissionDef

getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void;

W
wtt1995 已提交
2487
以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。
W
wanghang 已提交
2488 2489 2490 2491 2492 2493 2494 2495 2496

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

2497
| 参数名           | 类型                                                         | 必填 | 说明                                                         |
W
wanghang 已提交
2498
| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
J
junyi233 已提交
2499
| permissionName | string                                                       | 是   | 表示权限名称。                                               |
Z
zhaogan 已提交
2500
| callback       | AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<PermissionDef>;否则为错误对象。 |
W
wanghang 已提交
2501 2502 2503

**错误码:**

Z
zengyawen 已提交
2504
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2505

J
junyi233 已提交
2506 2507
| 错误码ID | 错误信息                              |
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2508
| 17700006 | The specified permission is not found. |
W
wanghang 已提交
2509 2510 2511 2512

**示例:**

```ts
L
Lotol 已提交
2513
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2514
import hilog from '@ohos.hilog';
W
wanghang 已提交
2515 2516 2517 2518
let permission = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permission, (err, data) => {
        if (err) {
L
longwei 已提交
2519
            hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message);
W
wanghang 已提交
2520
        } else {
L
longwei 已提交
2521
            hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2522 2523 2524
        }
    });
} catch (err) {
L
longwei 已提交
2525
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message);
W
wanghang 已提交
2526 2527 2528 2529 2530 2531 2532
}
```

### bundleManager.getPermissionDef

getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>;

W
wtt1995 已提交
2533
以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise形式返回结果。
W
wanghang 已提交
2534 2535 2536 2537 2538 2539 2540 2541 2542

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

2543
| 参数名           | 类型   | 必填 | 说明           |
J
junyi233 已提交
2544
| -------------- | ------ | ---- | -------------- |
Z
zhaogan 已提交
2545
| permissionName | string | 是   | 表示权限参数名。 |
W
wanghang 已提交
2546 2547 2548 2549 2550

**返回值:**

| 类型                                                         | 说明                                       |
| ------------------------------------------------------------ | ------------------------------------------ |
Z
zhaogan 已提交
2551
| Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | Promise对象,返回Array\<PermissionDef>对象。 |
W
wanghang 已提交
2552 2553 2554

**错误码:**

Z
zengyawen 已提交
2555
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2556

J
junyi233 已提交
2557 2558
| 错误码ID | 错误信息                              |
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2559
| 17700006 | The specified permission is not found. |
W
wanghang 已提交
2560 2561 2562 2563

**示例:**

```ts
L
Lotol 已提交
2564
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2565
import hilog from '@ohos.hilog';
W
wanghang 已提交
2566 2567 2568
let permissionName = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permissionName).then((data) => {
L
longwei 已提交
2569
        hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data));
2570
    }).catch(err => {
L
longwei 已提交
2571
        hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2572
    });
2573
} catch (err) {
L
longwei 已提交
2574
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591
}
```

### bundleManager.getAbilityLabel

getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<string>): void;

以异步的方法获取指定bundleName、moduleName和abilityName的label,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource

**参数:**

J
junyi233 已提交
2592
| 参数名      | 类型                   | 必填 | 说明                                                         |
W
wanghang 已提交
2593
| ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2594 2595 2596 2597
| bundleName  | string                 | 是   | 表示应用程序的bundleName。                                     |
| moduleName  | string                 | 是   | 表示应用程序的moduleName。                                     |
| abilityName | string                 | 是   | 表示应用程序的abilityName。                                    |
| callback    | AsyncCallback\<string> | 是   | 回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。 |
W
wanghang 已提交
2598 2599 2600

**错误码:**

Z
zengyawen 已提交
2601
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2602

J
junyi233 已提交
2603 2604
| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2605 2606 2607 2608 2609
| 17700001 | The specified bundleName is not found.  |
| 17700002 | The specified moduleName is not found.  |
| 17700003 | The specified abilityName is not found. |
| 17700026 | The specified bundle is disabled.       |
| 17700029 | The specified ability is disabled.      |
W
wanghang 已提交
2610 2611 2612 2613

**示例:**

```ts
L
Lotol 已提交
2614
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2615
import hilog from '@ohos.hilog';
W
wanghang 已提交
2616 2617
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
2618
let abilityName = 'EntryAbility';
W
wanghang 已提交
2619 2620 2621 2622

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => {
        if (err) {
L
longwei 已提交
2623
            hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message);
W
wanghang 已提交
2624
        } else {
L
longwei 已提交
2625
            hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2626 2627 2628
        }
    });
} catch (err) {
L
longwei 已提交
2629
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message);
W
wanghang 已提交
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
}
```

### bundleManager.getAbilityLabel

getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string>;

以异步的方法获取指定bundleName、moduleName和abilityName的label,使用Promise形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Resource

**参数:**

J
junyi233 已提交
2647
| 参数名      | 类型   | 必填 | 说明                      |
W
wanghang 已提交
2648
| ----------- | ------ | ---- | ------------------------- |
Z
zhaogan 已提交
2649 2650 2651
| bundleName  | string | 是   | 表示应用程序的bundleName。  |
| moduleName  | string | 是   | 表示应用程序的moduleName。  |
| abilityName | string | 是   | 表示应用程序的abilityName。 |
W
wanghang 已提交
2652 2653 2654 2655 2656

**返回值:**

| 类型             | 说明                                |
| ---------------- | ----------------------------------- |
Z
zhaogan 已提交
2657
| Promise\<string> | Promise对象,返回指定组件的Lablel值。 |
W
wanghang 已提交
2658 2659 2660

**错误码:**

Z
zengyawen 已提交
2661
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2662

J
junyi233 已提交
2663
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2664
| -------- | --------------------------------------- |
Z
zhaogan 已提交
2665 2666 2667 2668 2669
| 17700001 | The specified bundleName is not found.  |
| 17700002 | The specified moduleName is not found.  |
| 17700003 | The specified abilityName is not found. |
| 17700026 | The specified bundle is disabled.       |
| 17700029 | The specified ability is disabled.      |
W
wanghang 已提交
2670 2671 2672 2673

**示例:**

```ts
L
Lotol 已提交
2674
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2675
import hilog from '@ohos.hilog';
W
wanghang 已提交
2676 2677
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
2678
let abilityName = 'EntryAbility';
W
wanghang 已提交
2679 2680 2681

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => {
L
longwei 已提交
2682
        hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data));
2683
    }).catch(err => {
L
longwei 已提交
2684
        hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2685
    });
2686
} catch (err) {
L
longwei 已提交
2687
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2688 2689 2690 2691 2692 2693 2694 2695
}
```


### bundleManager.getApplicationInfoSync

getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);

W
wtt1995 已提交
2696
以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。
W
wanghang 已提交
2697 2698 2699 2700 2701

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

W
wtt1995 已提交
2702
**系统能力:** SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
2703 2704 2705

**参数:**

J
junyi233 已提交
2706
| 参数名       | 类型   | 必填 | 说明                                                       |
W
wanghang 已提交
2707
| ----------- | ------ | ---- | ----------------------------------------------------------|
Z
zhaogan 已提交
2708 2709
| bundleName  | string | 是   | 表示应用程序的bundleName。                                  |
| applicationFlags | [number](#applicationflag) | 是   | 表示用于指定将返回的ApplicationInfo对象中包含的信息。       |
L
Lotol 已提交
2710
| userId      | number | 是   | 表示用户ID。                                         |
W
wanghang 已提交
2711 2712 2713 2714 2715

**返回值:**

| 类型            | 说明                      |
| --------------- | ------------------------- |
Z
zhaogan 已提交
2716
| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 |
W
wanghang 已提交
2717 2718 2719

**错误码:**

Z
zengyawen 已提交
2720
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2721

J
junyi233 已提交
2722
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2723
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2724
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2725
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2726
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2727 2728 2729 2730

**示例:**

```ts
L
Lotol 已提交
2731
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2732
import hilog from '@ohos.hilog';
W
wanghang 已提交
2733 2734 2735 2736 2737 2738
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId);
L
longwei 已提交
2739
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2740
} catch (err) {
L
longwei 已提交
2741
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2742 2743 2744
}
```

J
junyi233 已提交
2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780
### bundleManager.getApplicationInfoSync

getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);

以同步方法根据给定的bundleName、applicationFlags获取ApplicationInfo。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

| 参数名           | 类型                       | 必填 | 说明                                                  |
| ---------------- | -------------------------- | ---- | ----------------------------------------------------- |
| bundleName       | string                     | 是   | 表示应用程序的bundleName。                            |
| applicationFlags | [number](#applicationflag) | 是   | 表示用于指定将返回的ApplicationInfo对象中包含的信息。 |

**返回值:**

| 类型                                                        | 说明                      |
| ----------------------------------------------------------- | ------------------------- |
| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 |

**错误码:**

以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)

| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700026 | The specified bundle is disabled.      |

**示例:**

W
wanghang 已提交
2781
```ts
L
Lotol 已提交
2782
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2783
import hilog from '@ohos.hilog';
W
wanghang 已提交
2784 2785 2786 2787 2788
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags);
L
longwei 已提交
2789
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2790
} catch (err) {
L
longwei 已提交
2791
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808
}
```

### bundleManager.getBundleInfoSync

getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md);

以同步方法根据给定的bundleName、bundleFlags和userId获取BundleInfo。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

J
junyi233 已提交
2809
| 参数名       | 类型   | 必填 | 说明                                                     |
W
wanghang 已提交
2810
| ----------- | ------ | ---- | -------------------------------------------------------- |
Z
zhaogan 已提交
2811 2812
| bundleName  | string | 是   | 表示应用程序的bundleName。                                 |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 |
J
junyi233 已提交
2813
| userId      | number | 是   | 表示用户ID。                                             |
W
wanghang 已提交
2814 2815 2816 2817 2818

**返回值:**

| 类型       | 说明                 |
| ---------- | -------------------- |
Z
zhaogan 已提交
2819
| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 |
W
wanghang 已提交
2820 2821 2822

**错误码:**

Z
zengyawen 已提交
2823
以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)
W
wanghang 已提交
2824

J
junyi233 已提交
2825
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2826
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2827
| 17700001 | The specified bundleName is not found. |
2828
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2829
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2830 2831 2832 2833

**示例:**

```ts
L
Lotol 已提交
2834
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2835
import hilog from '@ohos.hilog';
W
wanghang 已提交
2836 2837 2838 2839 2840 2841
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;

try {
    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
L
longwei 已提交
2842
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2843
} catch (err) {
L
longwei 已提交
2844
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2845 2846 2847
}
```

J
junyi233 已提交
2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883
### bundleManager.getBundleInfoSync

getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md);

以同步方法根据给定的bundleName、bundleFlags获取BundleInfo。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

| 参数名      | 类型                  | 必填 | 说明                                                   |
| ----------- | --------------------- | ---- | ------------------------------------------------------ |
| bundleName  | string                | 是   | 表示应用程序的bundleName。                             |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 |

**返回值:**

| 类型                                              | 说明                 |
| ------------------------------------------------- | -------------------- |
| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 |

**错误码:**

以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)

| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700026 | The specified bundle is disabled.      |

**示例:**

W
wanghang 已提交
2884
```ts
L
Lotol 已提交
2885
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2886
import hilog from '@ohos.hilog';
W
wanghang 已提交
2887 2888 2889
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
try {
Z
zhaogan 已提交
2890
    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags);
L
longwei 已提交
2891
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2892
} catch (err) {
L
longwei 已提交
2893
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2894
}
Z
zhongjianfei 已提交
2895
```
J
junyi233 已提交
2896

2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914
### bundleManager.getSharedBundleInfo<sup>10+</sup>

getSharedBundleInfo(bundleName: string,  moduleName: string, callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void;

以异步的方法获取指定的共享包信息,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

| 参数名     | 类型                                                         | 必填 | 说明                                                         |
| ---------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| bundleName | string                                                       | 是   | 表示应用程序的bundleName。                                   |
| moduleName | string                                                       | 是   | 表示被查询的module的name。                                   |
2915
| callback   | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | 是   | 回调函数,当获取成功时,err为null,data为获取的指定共享包信息。 |
2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969

**错误码:**

以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)

| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified moduleName is not found. |

**示例:**

```ts
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'library';

try {
    bundleManager.getSharedBundleInfo(bundleName, moduleName, (err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed: %{public}s', err.message);
}
```

### bundleManager.getSharedBundleInfo<sup>10+</sup>

function getSharedBundleInfo(bundleName: string, moduleName: string): Promise\<Array\<SharedBundleInfo\>\>;

以异步的方法获取指定的共享包信息,使用Promise形式返回结果。

**系统接口:** 此接口为系统接口

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

| 参数名     | 类型   | 必填 | 说明                       |
| ---------- | ------ | ---- | -------------------------- |
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| moduleName | string | 是   | 表示被查询的module的name。 |

**返回值:**

| 类型                                                         | 说明                                |
| ------------------------------------------------------------ | ----------------------------------- |
2970
| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Promise对象,返回指定的共享包信息。 |
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071

**错误码:**

以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)

| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified moduleName is not found. |

**示例:**

```ts
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';
let bundleName = 'com.example.myapplication';
let moduleName = 'library';

try {
    bundleManager.getSharedBundleInfo(bundleName, moduleName).then((data) => {
        hilog.info(0x0000, 'testTag', 'getSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch(err => {
        hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getSharedBundleInfo failed. Cause: %{public}s', err.message);
}
```

### bundleManager.getAllSharedBundleInfo<sup>10+</sup>

getAllSharedBundleInfo(callback: AsyncCallback\<Array\<SharedBundleInfo\>\>): void;

以异步的方法获取所有的共享包信息,使用callback形式返回结果。

**系统接口:** 此接口为系统接口。

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**参数:**

| 参数名   | 类型                                                         | 必填 | 说明                                                         |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | 是   | 回调函数,当获取成功时,err为null,data为获所有的共享包信息。 |

**示例:**

```ts
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';

try {
    bundleManager.getAllSharedBundleInfo((err, data) => {
        if (err) {
            hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', err.message);
        } else {
            hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully: %{public}s', JSON.stringify(data));
        }
    });
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed: %{public}s', err.message);
}
```

### bundleManager.getAllSharedBundleInfo<sup>10+</sup>

function getAllSharedBundleInfo(): Promise\<Array\<SharedBundleInfo\>\>;

以异步的方法获取所有的共享包信息,使用Promise形式返回结果。

**系统接口:** 此接口为系统接口

**需要权限:** ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**系统能力:** SystemCapability.BundleManager.BundleFramework.Core

**返回值:**

| 类型                                                         | 说明                                |
| ------------------------------------------------------------ | ----------------------------------- |
| Promise\<Array\<[SharedBundleInfo](js-apis-bundleManager-sharedBundleInfo.md)\>\> | Promise对象,返回所有的共享包信息。 |

**示例:**

```ts
import bundleManager from '@ohos.bundle.bundleManager';
import hilog from '@ohos.hilog';

try {
    bundleManager.getAllSharedBundleInfo().then((data) => {
        hilog.info(0x0000, 'testTag', 'getAllSharedBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
    }).catch(err => {
        hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', err.message);
    });
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getAllSharedBundleInfo failed. Cause: %{public}s', err.message);
}
```