js-apis-bundleManager.md 119.9 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 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 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 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 114
| ENTERPRISE_ADMIN |  11 | [EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md):企业设备管理扩展能力,提供企业管理时处理管理事件的能力,比如设备上应用安装事件、锁屏密码输入错误次数过多事件等。 |
| THUMBNAIL        | 13  | ThumbnailExtensionAbility:文件缩略图扩展能力,用于为文件提供图标缩略图的能力。预留能力,当前暂未支持。 |
| PREVIEW          | 14  | PreviewExtensionAbility:文件预览扩展能力,提供文件预览的能力,其他应用可以直接在应用中嵌入显示。预留能力,当前暂未支持。 |
| UNSPECIFIED      | 255 | 不指定类型,配合queryExtensionAbilityInfo接口可以查询所有类型的ExtensionAbility。 |
W
wanghang 已提交
115 116 117 118


### PermissionGrantState

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

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

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

### SupportWindowMode

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

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

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

### LaunchType

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

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

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

### AbilityType

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

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

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

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

### DisplayOrientation

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

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

J
junyi233 已提交
172 173
| 名称                               |值 |说明 |
|:----------------------------------|---|---|
Z
zhaogan 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186
| 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 已提交
187

W
wtt1995 已提交
188
## 接口
W
wanghang 已提交
189 190 191 192 193 194 195 196 197 198 199

### bundleManager.getBundleInfoForSelf

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

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

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

**参数:**

J
junyi233 已提交
200
| 参数名     | 类型   | 必填 | 说明                |
W
wanghang 已提交
201
| ----------- | ------ | ---- | --------------------- |
Z
zhaogan 已提交
202
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。 |
W
wanghang 已提交
203 204 205 206 207

**返回值:**

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

Z
zhaogan 已提交
210 211
**示例:**

W
wanghang 已提交
212
```ts
L
Lotol 已提交
213
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
214
import hilog from '@ohos.hilog';
W
wanghang 已提交
215 216 217
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
    bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
G
geng-wenguang 已提交
218
        hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data));
219 220
    }).catch(err => {
        hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
W
wanghang 已提交
221
    });
222 223
} catch (err) {
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
W
wanghang 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236
}
```

### bundleManager.getBundleInfoForSelf

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

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

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

**参数:**

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

**示例:**

```ts
L
Lotol 已提交
245
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
246
import hilog from '@ohos.hilog';
W
wanghang 已提交
247 248 249 250 251
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
        if (err) {
252
            hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
W
wanghang 已提交
253
        } else {
G
geng-wenguang 已提交
254
            hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
255 256 257
        }
    });
} catch (err) {
258
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', err.message);
W
wanghang 已提交
259 260 261 262 263 264 265 266 267
}
```

### bundleManager.getBundleInfo

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

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

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

W
wanghang 已提交
270 271 272 273 274 275 276 277
**系统接口:** 此接口为系统接口。

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
289
| 错误码ID | 错误信息                              |
W
wanghang 已提交
290
| -------- | ------------------------------------- |
Z
zhaogan 已提交
291
| 17700001 | The specified bundleName is not found. |
292
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
293
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
294 295 296 297

**示例:**

```ts
J
junyi233 已提交
298
// 额外获取AbilityInfo
L
Lotol 已提交
299
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
300
import hilog from '@ohos.hilog';
W
wanghang 已提交
301
let bundleName = 'com.example.myapplication';
J
junyi233 已提交
302 303 304 305 306 307
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 已提交
308
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
J
junyi233 已提交
309
        } else {
L
longwei 已提交
310
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
J
junyi233 已提交
311 312 313
        }
    });
} catch (err) {
L
longwei 已提交
314
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
J
junyi233 已提交
315 316 317
}
```

Z
zhaogan 已提交
318
```ts
J
junyi233 已提交
319
// 额外获取ApplicationInfo中的metadata
L
Lotol 已提交
320
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
321
import hilog from '@ohos.hilog';
J
junyi233 已提交
322 323
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
W
wanghang 已提交
324 325 326 327 328
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
329
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
330
        } else {
L
longwei 已提交
331
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
332 333 334
        }
    });
} catch (err) {
L
longwei 已提交
335
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
336 337 338 339 340 341 342 343 344
}
```

### bundleManager.getBundleInfo

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

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

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

W
wanghang 已提交
347 348 349 350 351 352 353 354
**系统接口:** 此接口为系统接口。

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
365
| 错误码ID | 错误信息                              |
W
wanghang 已提交
366
| -------- | ------------------------------------- |
Z
zhaogan 已提交
367
| 17700001 | The specified bundleName is not found. |
368
| 17700004 | The specified user ID is not found.    |
Z
zhaogan 已提交
369
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
370 371 372 373

**示例:**

```ts
J
junyi233 已提交
374
// 额外获取extensionAbility
L
Lotol 已提交
375
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
376
import hilog from '@ohos.hilog';
W
wanghang 已提交
377
let bundleName = 'com.example.myapplication';
J
junyi233 已提交
378
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY;
W
wanghang 已提交
379 380 381 382

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => {
        if (err) {
L
longwei 已提交
383
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
384
        } else {
L
longwei 已提交
385
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
386 387 388
        }
    });
} catch (err) {
L
longwei 已提交
389
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
390 391 392 393 394 395 396 397 398
}
```

### 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 已提交
399 400
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
401 402 403 404 405 406 407 408
**系统接口:** 此接口为系统接口。

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

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

**参数:**

J
junyi233 已提交
409
| 参数名     | 类型   | 必填 | 说明                       |
W
wanghang 已提交
410
| ----------- | ------ | ---- | ---------------------------- |
411
| bundleName  | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
412 413
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。       |
| userId      | number | 否   | 表示用户ID。  |
W
wanghang 已提交
414 415 416 417 418

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
425
| 错误码ID | 错误信息                            |
W
wanghang 已提交
426
| -------- | --------------------------------------|
Z
zhaogan 已提交
427
| 17700001 | The specified bundleName is not found. |
428
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
429
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
430 431 432 433

**示例:**

```ts
J
junyi233 已提交
434
// 额外获取ApplicationInfo和SignatureInfo
L
Lotol 已提交
435
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
436
import hilog from '@ohos.hilog';
W
wanghang 已提交
437
let bundleName = 'com.example.myapplication';
J
junyi233 已提交
438
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
W
wanghang 已提交
439 440 441 442
let userId = 100;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => {
L
longwei 已提交
443
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
444
    }).catch(err => {
L
longwei 已提交
445
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
446
    });
447
} catch (err) {
L
longwei 已提交
448
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
449 450 451 452
}
```

```ts
L
Lotol 已提交
453
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
454
import hilog from '@ohos.hilog';
W
wanghang 已提交
455 456 457 458 459
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => {
L
longwei 已提交
460
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
461
    }).catch(err => {
L
longwei 已提交
462
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
463
    });
464
} catch (err) {
L
longwei 已提交
465
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
466 467 468 469 470 471 472 473 474 475
}

```

### 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 已提交
476 477
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
478 479 480 481 482 483 484 485
**系统接口:** 此接口为系统接口。

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
497
| 错误码ID | 错误信息                             |
W
wanghang 已提交
498
| -------- | --------------------------------------|
Z
zhaogan 已提交
499
| 17700001 | The specified bundleName is not found. |
500
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
501
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
502

503
**示例:** 
W
wanghang 已提交
504 505

```ts
L
Lotol 已提交
506
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
507
import hilog from '@ohos.hilog';
W
wanghang 已提交
508 509 510 511 512 513 514
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 已提交
515
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
516
        } else {
L
longwei 已提交
517
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
518 519 520
        }
    });
} catch (err) {
L
longwei 已提交
521
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
522 523 524 525 526 527 528 529 530
}
```

### bundleManager.getApplicationInfo

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

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

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

W
wanghang 已提交
533 534 535 536 537 538 539 540
**系统接口:** 此接口为系统接口。

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
551
| 错误码ID | 错误信息                             |
W
wanghang 已提交
552
| -------- | --------------------------------------|
Z
zhaogan 已提交
553
| 17700001 | The specified bundleName is not found. |
554
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
555
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
556 557 558 559

**示例:**

```ts
L
Lotol 已提交
560
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
561
import hilog from '@ohos.hilog';
W
wanghang 已提交
562
let bundleName = 'com.example.myapplication';
Z
zhaogan 已提交
563
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
W
wanghang 已提交
564 565 566 567

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => {
        if (err) {
L
longwei 已提交
568
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
569
        } else {
L
longwei 已提交
570
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
571 572 573
        }
    });
} catch (err) {
L
longwei 已提交
574
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
575 576 577 578 579 580 581 582 583
}
```

### 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 已提交
584 585
获取调用方自己的信息时不需要权限。

W
wanghang 已提交
586 587 588 589 590 591 592 593
**系统接口:** 此接口为系统接口。

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

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

**参数:**

J
junyi233 已提交
594
| 参数名    | 类型   | 必填 | 说明                       |
W
wanghang 已提交
595
| ---------- | ------ | ---- | ---------------------------- |
596
| bundleName | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
597 598
| appFlags   | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。    |
| userId     | number | 否   | 表示用户ID。 |
W
wanghang 已提交
599 600 601 602 603

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
610
| 错误码ID | 错误信息                             |
W
wanghang 已提交
611
| -------- | ------------------------------------- |
Z
zhaogan 已提交
612
| 17700001 | The specified bundleName is not found. |
613
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
614
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
615 616 617 618

**示例:**

```ts
L
Lotol 已提交
619
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
620
import hilog from '@ohos.hilog';
W
wanghang 已提交
621 622 623 624 625 626
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 已提交
627
        hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', JSON.stringify(data));
628
    }).catch(err => {
L
longwei 已提交
629
        hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
630
    });
631
} catch (err) {
L
longwei 已提交
632
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
633 634 635 636 637 638 639
}
```

### bundleManager.getAllBundleInfo

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

W
wtt1995 已提交
640
以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。
W
wanghang 已提交
641 642 643 644 645 646 647 648 649

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
660
| 错误码ID | 错误信息                         |
W
wanghang 已提交
661
| -------- | --------------------------------- |
662
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
663 664 665 666

**示例:**

```ts
L
Lotol 已提交
667
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
668
import hilog from '@ohos.hilog';
W
wanghang 已提交
669 670 671 672 673 674
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;

try {
    bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
675
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
676
        } else {
L
longwei 已提交
677
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
678 679 680
        }
    });
} catch (err) {
L
longwei 已提交
681
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
682 683 684 685 686 687 688
}
```

### bundleManager.getAllBundleInfo

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

W
wtt1995 已提交
689
以异步方法根据给定的bundleFlags获取系统中所有的BundleInfo,使用callback形式返回结果。
W
wanghang 已提交
690 691 692 693 694 695 696 697 698

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

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

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

**参数:**

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

**错误码:**

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

708 709 710 711
| 错误码ID | 错误信息                         |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |

W
wanghang 已提交
712 713 714
**示例:**

```ts
L
Lotol 已提交
715
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
716
import hilog from '@ohos.hilog';
W
wanghang 已提交
717 718 719 720 721
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags, (err, data) => {
        if (err) {
L
longwei 已提交
722
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
723
        } else {
L
longwei 已提交
724
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
725 726 727
        }
    });
} catch (err) {
L
longwei 已提交
728
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s', err.message);
W
wanghang 已提交
729 730 731 732 733 734 735
}
```

### bundleManager.getAllBundleInfo

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

W
wtt1995 已提交
736
以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用Promise形式返回结果。
W
wanghang 已提交
737 738 739 740 741 742 743 744 745

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

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

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

**参数:**

J
junyi233 已提交
746
| 参数名     | 类型   | 必填 | 说明                                             |
W
wanghang 已提交
747
| ----------- | ------ | ---- | -------------------------------------------------- |
Z
zhaogan 已提交
748 749
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。                   |
| userId      | number | 否   | 表示用户ID。                         |
W
wanghang 已提交
750 751 752 753 754

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
761
| 错误码ID | 错误信息                         |
W
wanghang 已提交
762
| -------- | ---------------------------------- |
763
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
764 765 766 767

**示例:**

```ts
L
Lotol 已提交
768
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
769
import hilog from '@ohos.hilog';
W
wanghang 已提交
770 771 772 773
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags).then((data) => {
L
longwei 已提交
774
        hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', JSON.stringify(data));
775
    }).catch(err => {
L
longwei 已提交
776
        hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
777
    });
778
} catch (err) {
L
longwei 已提交
779
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
780 781 782 783 784 785 786
}
```

### bundleManager.getAllApplicationInfo

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

W
wtt1995 已提交
787
以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。
W
wanghang 已提交
788 789 790 791 792 793 794 795 796

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
807
| 错误码ID | 错误信息                         |
W
wanghang 已提交
808
| -------- | ---------------------------------- |
809
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
810 811 812 813

**示例:**

```ts
L
Lotol 已提交
814
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
815
import hilog from '@ohos.hilog';
W
wanghang 已提交
816 817 818 819 820 821
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
822
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
823
        } else {
L
longwei 已提交
824
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
825 826 827
        }
    });
} catch (err) {
L
longwei 已提交
828
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
829 830 831 832 833 834 835
}
```

### bundleManager.getAllApplicationInfo

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

W
wtt1995 已提交
836
以异步方法根据给定的appFlags获取系统中所有的ApplicationInfo,使用callback形式返回结果。
W
wanghang 已提交
837 838 839 840 841 842 843 844 845

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

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

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

**参数:**

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

**错误码:**

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

855 856 857 858
| 错误码ID | 错误信息                         |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |

W
wanghang 已提交
859 860 861
**示例:**

```ts
L
Lotol 已提交
862
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
863
import hilog from '@ohos.hilog';
W
wanghang 已提交
864 865 866 867 868
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags, (err, data) => {
        if (err) {
L
longwei 已提交
869
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
870
        } else {
L
longwei 已提交
871
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
872 873 874
        }
    });
} catch (err) {
L
longwei 已提交
875
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s', err.message);
W
wanghang 已提交
876 877 878 879 880 881 882
}
```

### bundleManager.getAllApplicationInfo

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

W
wtt1995 已提交
883
以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用Promise形式返回结果。
W
wanghang 已提交
884 885 886 887 888 889 890 891 892

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

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

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

**参数:**

J
junyi233 已提交
893
| 参数名  | 类型   | 必填 | 说明                                                      |
W
wanghang 已提交
894
| -------- | ------ | ---- | ---------------------------------------------------------- |
Z
zhaogan 已提交
895 896
| appFlags | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。                       |
| userId   | number | 否   | 表示用户ID。                                  |
W
wanghang 已提交
897 898 899 900 901

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
908
| 错误码ID | 错误信息                         |
W
wanghang 已提交
909
| -------- | ---------------------------------- |
910
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
911 912 913 914

**示例:**

```ts
L
Lotol 已提交
915
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
916
import hilog from '@ohos.hilog';
W
wanghang 已提交
917 918 919 920
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags).then((data) => {
L
longwei 已提交
921
        hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', JSON.stringify(data));
922
    }).catch(err => {
L
longwei 已提交
923
        hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
924
    });
925
} catch (err) {
L
longwei 已提交
926
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
}

```

### 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 已提交
945
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
946
| ------------ | ------ | ---- | ------------------------------------------------------- |
947
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
948 949 950
| abilityFlags | [number](#abilityflag) | 是   | 指定返回的AbilityInfo所包含的信息。                       |
| userId       | number | 是   | 表示用户ID。                               |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
951 952 953

**错误码:**

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

J
junyi233 已提交
956
| 错误码ID | 错误信息                             |
W
wanghang 已提交
957
| -------- | -------------------------------------- |
Z
zhaogan 已提交
958 959 960 961 962
| 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 已提交
963 964 965 966

**示例:**

```ts
L
Lotol 已提交
967
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
968
import hilog from '@ohos.hilog';
W
wanghang 已提交
969 970 971 972
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
973
    abilityName : "EntryAbility"
W
wanghang 已提交
974 975 976 977 978
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
979
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
980
        } else {
L
longwei 已提交
981
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
982 983 984
        }
    });
} catch (err) {
L
longwei 已提交
985
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
}
```

### 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 已提交
1003
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
1004
| ------------ | ------ | ---- | -------------------------------------------------------|
1005
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
1006 1007
| abilityFlags | [number](#abilityflag) | 是   | 指定返回的AbilityInfo所包含的信息。       |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | 是 | 回调函数,当获取成功时,err为null,data为获取到的Array\<AbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
1008 1009 1010

**错误码:**

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

J
junyi233 已提交
1013
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1014
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1015 1016
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified ability is not found.    |
1017
| 17700004 | The specified userId is invalid.       |
Z
zhaogan 已提交
1018 1019
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
1020 1021 1022 1023

**示例:**

```ts
L
Lotol 已提交
1024
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1025
import hilog from '@ohos.hilog';
W
wanghang 已提交
1026 1027 1028
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1029
    abilityName : "EntryAbility"
W
wanghang 已提交
1030 1031 1032 1033 1034
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => {
        if (err) {
L
longwei 已提交
1035
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1036
        } else {
L
longwei 已提交
1037
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1038 1039 1040
        }
    });
} catch (err) {
L
longwei 已提交
1041
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
}
```

### 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 已提交
1059
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
1060
| ------------ | ------ | ---- | ------------------------------------------------------- |
1061
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
1062 1063
| abilityFlags | [number](#abilityflag) | 是   | 表示指定返回的AbilityInfo所包含的信息。 |
| userId       | number | 否   | 表示用户ID。                               |
W
wanghang 已提交
1064 1065 1066 1067 1068

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1075
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1076
| -------- | ------------------------------------- |
Z
zhaogan 已提交
1077
| 17700001 | The specified bundleName is not found. |
1078
| 17700003 | The specified extensionAbility is not found.    |
Z
zhaogan 已提交
1079 1080 1081
| 17700004 | The specified userId is invalid.       |
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
1082 1083 1084 1085

**示例:**

```ts
L
Lotol 已提交
1086
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1087
import hilog from '@ohos.hilog';
W
wanghang 已提交
1088 1089 1090 1091
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1092
    abilityName : "EntryAbility"
W
wanghang 已提交
1093 1094 1095 1096
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => {
L
longwei 已提交
1097
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1098
    }).catch(err => {
L
longwei 已提交
1099
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1100
    });
1101
} catch (err) {
L
longwei 已提交
1102
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1103 1104 1105 1106
}
```

```ts
L
Lotol 已提交
1107
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1108
import hilog from '@ohos.hilog';
W
wanghang 已提交
1109 1110 1111
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1112
    abilityName : "EntryAbility"
W
wanghang 已提交
1113 1114 1115 1116
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => {
L
longwei 已提交
1117
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1118
    }).catch(err => {
L
longwei 已提交
1119
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1120
    })
1121
} catch (err) {
L
longwei 已提交
1122
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
}
```

### 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 已提交
1140
| 参数名                | 类型                                                         | 必填 | 说明                                                         |
W
wanghang 已提交
1141
| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1142 1143 1144 1145
| want                  | Want                                                         | 是   | 表示包含要查询的应用Bundle名称的Want。                       |
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype)                | 是   | 标识extensionAbility的类型。                                 |
| extensionAbilityFlags | [number](#extensionabilityflag)                              | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。    |
| userId                | number                                                       | 是   | 表示用户ID。                                                 |
Z
zhaogan 已提交
1146
| callback              | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是   | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
1147 1148 1149

**错误码:**

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

J
junyi233 已提交
1152 1153
| 错误码ID | 错误信息                                    |
| -------- | ------------------------------------------- |
Z
zhaogan 已提交
1154 1155 1156 1157
| 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 已提交
1158 1159 1160 1161

**示例:**

```ts
L
Lotol 已提交
1162
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1163
import hilog from '@ohos.hilog';
W
wanghang 已提交
1164 1165 1166 1167 1168
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1169
    abilityName : "EntryAbility"
W
wanghang 已提交
1170 1171 1172 1173 1174
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => {
        if (err) {
L
longwei 已提交
1175
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1176
        } else {
L
longwei 已提交
1177
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1178 1179 1180
        }
    });
} catch (err) {
L
longwei 已提交
1181
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
}
```

### 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 已提交
1199
| 参数名                | 类型                                                         | 必填 | 说明                                                         |
W
wanghang 已提交
1200
| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1201 1202 1203
| want                  | Want                                                         | 是   | 表示包含要查询的应用Bundle名称的Want。                       |
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype)                | 是   | 标识extensionAbility的类型。                                 |
| extensionAbilityFlags | [number](#extensionabilityflag)                              | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。    |
Z
zhaogan 已提交
1204
| callback              | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | 是   | 回调函数,当获取成功时,err为null,data为获取到Array\<ExtensionAbilityInfo>;否则为错误对象。 |
W
wanghang 已提交
1205 1206 1207

**错误码:**

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

J
junyi233 已提交
1210 1211
| 错误码ID | 错误信息                                     |
| -------- | -------------------------------------------- |
Z
zhaogan 已提交
1212 1213
| 17700001 | The specified bundleName is not found.       |
| 17700003 | The specified extensionAbility is not found. |
1214
| 17700004 | The specified userId is invalid.       |
Z
zhaogan 已提交
1215
| 17700026 | The specified bundle is disabled.            |
W
wanghang 已提交
1216 1217 1218 1219

**示例:**

```ts
L
Lotol 已提交
1220
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1221
import hilog from '@ohos.hilog';
W
wanghang 已提交
1222 1223 1224 1225
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1226
    abilityName : "EntryAbility"
W
wanghang 已提交
1227 1228 1229 1230 1231
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => {
        if (err) {
L
longwei 已提交
1232
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1233
        } else {
L
longwei 已提交
1234
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1235 1236 1237
        }
    });
} catch (err) {
L
longwei 已提交
1238
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s', err.message);
W
wanghang 已提交
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
}
```

### 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

**参数:**

1256 1257 1258
| 参数名                | 类型                                          | 必填 | 说明                                                      |
| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- |
| want                  | Want                                          | 是   | 表示包含要查询的应用Bundle名称的Want。                    |
Z
zhaogan 已提交
1259 1260 1261
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype) | 是   | 标识extensionAbility的类型。                              |
| extensionAbilityFlags | [number](#extensionabilityflag)               | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 |
| userId                | number                                        | 否   | 表示用户ID。                                              |
W
wanghang 已提交
1262 1263 1264 1265 1266

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1273
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1274
| -------- | --------------------------------------|
Z
zhaogan 已提交
1275 1276 1277 1278
| 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 已提交
1279 1280 1281 1282

**示例:**

```ts
L
Lotol 已提交
1283
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1284
import hilog from '@ohos.hilog';
W
wanghang 已提交
1285 1286 1287 1288 1289 1290

let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1291
    abilityName : "EntryAbility"
W
wanghang 已提交
1292 1293 1294 1295
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => {
L
longwei 已提交
1296
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1297
    }).catch(err => {
L
longwei 已提交
1298
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1299
    });
1300
} catch (err) {
L
longwei 已提交
1301
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1302 1303 1304 1305
}
```

```ts
L
Lotol 已提交
1306
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1307
import hilog from '@ohos.hilog';
W
wanghang 已提交
1308 1309 1310 1311
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
1312
    abilityName : "EntryAbility"
W
wanghang 已提交
1313 1314 1315 1316
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => {
L
longwei 已提交
1317
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', JSON.stringify(data));
1318
    }).catch(err => {
L
longwei 已提交
1319
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1320
    })
1321
} catch (err) {
L
longwei 已提交
1322
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1323 1324 1325 1326 1327 1328 1329
}
```

### bundleManager.getBundleNameByUid

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

W
wtt1995 已提交
1330
以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。
W
wanghang 已提交
1331 1332 1333 1334 1335 1336 1337 1338 1339

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1349
| 错误码ID | 错误信息            |
W
wanghang 已提交
1350
| -------- | --------------------- |
Z
zhaogan 已提交
1351
| 17700021 | The uid is not found. |
W
wanghang 已提交
1352 1353 1354 1355

**示例:**

```ts
L
Lotol 已提交
1356
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1357
import hilog from '@ohos.hilog';
W
wanghang 已提交
1358 1359 1360 1361
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid, (err, data) => {
        if (err) {
L
longwei 已提交
1362
            hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message);
W
wanghang 已提交
1363
        } else {
L
longwei 已提交
1364
            hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1365 1366 1367
        }
    });
} catch (err) {
L
longwei 已提交
1368
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s', err.message);
W
wanghang 已提交
1369 1370 1371 1372 1373 1374 1375
}
```

### bundleManager.getBundleNameByUid

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

W
wtt1995 已提交
1376
以异步方法根据给定的uid获取对应的bundleName,使用Promise形式返回结果。
W
wanghang 已提交
1377 1378 1379 1380 1381 1382 1383 1384 1385

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

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

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

**参数:**

J
junyi233 已提交
1386
| 参数名 | 类型   | 必填 | 说明                |
W
wanghang 已提交
1387
| ---- | ------ | ---- | ------------------ |
Z
zhaogan 已提交
1388
| uid  | number | 是   | 表示应用程序的UID。 |
W
wanghang 已提交
1389 1390 1391 1392 1393

**返回值:**

| 类型             | 说明                        |
| ---------------- | --------------------------- |
Z
zhaogan 已提交
1394
| Promise\<string> | Promise对象,返回bundleName。 |
W
wanghang 已提交
1395 1396 1397

**错误码:**

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

J
junyi233 已提交
1400
| 错误码ID | 错误信息            |
W
wanghang 已提交
1401
| -------- | ---------------------|
Z
zhaogan 已提交
1402
| 17700021 | The uid is not found. |
W
wanghang 已提交
1403 1404 1405 1406

**示例:**

```ts
L
Lotol 已提交
1407
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1408
import hilog from '@ohos.hilog';
W
wanghang 已提交
1409 1410 1411
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid).then((data) => {
L
longwei 已提交
1412
        hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', JSON.stringify(data));
1413
    }).catch(err => {
L
longwei 已提交
1414
        hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1415
    });
1416
} catch (err) {
L
longwei 已提交
1417
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
}
```

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

**错误码:**

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

J
junyi233 已提交
1445
| 错误码ID | 错误信息                  |
W
wanghang 已提交
1446
| -------- | --------------------------- |
Z
zhaogan 已提交
1447
| 17700022 | The hapFilePath is invalid. |
W
wanghang 已提交
1448 1449 1450 1451

**示例:**

```ts
L
Lotol 已提交
1452
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1453
import hilog from '@ohos.hilog';
W
wanghang 已提交
1454 1455 1456 1457 1458 1459
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 已提交
1460
            hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1461
        } else {
L
longwei 已提交
1462
            hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1463 1464 1465
        }
    });
} catch (err) {
L
longwei 已提交
1466
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
}
```

### 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 已提交
1484
| 参数名       | 类型   | 必填 | 说明                                                         |
W
wanghang 已提交
1485
| ----------- | ------ | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1486 1487
| hapFilePath | string | 是   | 表示存储HAP的路径,路径应该是当前应用程序数据目录的相对路径。 |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定要返回的BundleInfo对象中包含的信息的标志。       |
W
wanghang 已提交
1488 1489 1490 1491 1492

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1499
| 错误码ID | 错误信息                   |
W
wanghang 已提交
1500
| -------- | -------------------------- |
Z
zhaogan 已提交
1501
| 17700022 | The hapFilePath is invalid. |
W
wanghang 已提交
1502 1503 1504 1505

**示例:**

```ts
L
Lotol 已提交
1506
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1507
import hilog from '@ohos.hilog';
W
wanghang 已提交
1508 1509 1510 1511 1512
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => {
L
longwei 已提交
1513
        hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', JSON.stringify(data));
1514
    }).catch(err => {
L
longwei 已提交
1515
        hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1516
    });
1517
} catch (err) {
L
longwei 已提交
1518
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1519 1520 1521 1522 1523 1524 1525
}
```

### bundleManager.cleanBundleCacheFiles

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

W
wtt1995 已提交
1526
以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。
W
wanghang 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1545
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
1546
| -------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1547
| 17700001 | The specified bundleName is not found.                        |
1548
| 17700030 | The specified bundle does not support clearing of cache files. |
W
wanghang 已提交
1549 1550 1551 1552

**示例:**

```ts
L
Lotol 已提交
1553
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1554
import hilog from '@ohos.hilog';
W
wanghang 已提交
1555 1556 1557 1558 1559
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.cleanBundleCacheFiles(bundleName, err => {
        if (err) {
L
longwei 已提交
1560
            hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1561
        } else {
G
geng-wenguang 已提交
1562
            hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
W
wanghang 已提交
1563 1564 1565
        }
    });
} catch (err) {
L
longwei 已提交
1566
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1567 1568 1569 1570 1571 1572 1573
}
```

### bundleManager.cleanBundleCacheFiles

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

W
wtt1995 已提交
1574
以异步方法根据给定的bundleName清理BundleCache,使用Promise形式返回结果。
W
wanghang 已提交
1575 1576 1577 1578 1579 1580 1581 1582 1583

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

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

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

**参数:**

J
junyi233 已提交
1584 1585
| 参数名     | 类型   | 必填 | 说明                                       |
| ---------- | ------ | ---- | ------------------------------------------ |
Z
zhaogan 已提交
1586
| bundleName | string | 是   | 表示要清理其缓存数据的应用程序的bundleName。 |
W
wanghang 已提交
1587 1588 1589 1590 1591

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1598 1599
| 错误码ID | 错误信息                                                   |
| -------- | ---------------------------------------------------------- |
Z
zhaogan 已提交
1600
| 17700001 | The specified bundleName is not found.                      |
J
junyi233 已提交
1601
| 17700030 | The specified bundle does not support clearing of cache files. |
W
wanghang 已提交
1602 1603 1604 1605

**示例:**

```ts
L
Lotol 已提交
1606
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1607
import hilog from '@ohos.hilog';
W
wanghang 已提交
1608 1609 1610
let bundleName = "com.ohos.myapplication";

try {
W
wtt1995 已提交
1611
    bundleManager.cleanBundleCacheFiles(bundleName).then(() => {
G
geng-wenguang 已提交
1612
        hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
W
wtt1995 已提交
1613
    }).catch(err => {
L
longwei 已提交
1614
        hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1615 1616
    });
} catch (err) {
L
longwei 已提交
1617
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s', err.message);
W
wanghang 已提交
1618 1619 1620 1621 1622 1623 1624
}
```

### bundleManager.setApplicationEnabled

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

W
wtt1995 已提交
1625
设置指定应用的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1626 1627 1628 1629 1630 1631 1632 1633 1634

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1645
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1646
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1647
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1648 1649 1650 1651

**示例:**

```ts
L
Lotol 已提交
1652
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1653
import hilog from '@ohos.hilog';
W
wanghang 已提交
1654 1655 1656 1657 1658
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.setApplicationEnabled(bundleName, false, err => {
        if (err) {
L
longwei 已提交
1659
            hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1660
        } else {
G
geng-wenguang 已提交
1661
            hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.');
W
wanghang 已提交
1662 1663 1664
        }
    });
} catch (err) {
L
longwei 已提交
1665
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1666 1667 1668 1669 1670 1671 1672
}
```

### bundleManager.setApplicationEnabled

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

W
wtt1995 已提交
1673
设置指定应用的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1674 1675 1676 1677 1678 1679 1680 1681 1682

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

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

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

**参数:**

J
junyi233 已提交
1683
| 参数名      | 类型    | 必填 | 说明                                  |
W
wanghang 已提交
1684
| ---------- | ------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1685 1686
| bundleName | string  | 是   | 表示应用程序的bundleName。            |
| isEnabled  | boolean | 是   | 值为true表示使能,值为false表示禁用。 |
W
wanghang 已提交
1687 1688 1689 1690 1691

**返回值:**

| 类型           | 说明                                 |
| -------------- | ------------------------------------ |
Z
zhaogan 已提交
1692
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
W
wanghang 已提交
1693 1694 1695

**错误码:**

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

J
junyi233 已提交
1698
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1699
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1700
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1701 1702 1703 1704

**示例:**

```ts
L
Lotol 已提交
1705
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1706
import hilog from '@ohos.hilog';
W
wanghang 已提交
1707 1708 1709
let bundleName = "com.ohos.myapplication";

try {
W
wtt1995 已提交
1710
    bundleManager.setApplicationEnabled(bundleName, false).then(() => {
G
geng-wenguang 已提交
1711
        hilog.info(0x0000, "testTag", "setApplicationEnabled successfully.");
W
wtt1995 已提交
1712
    }).catch(err => {
L
longwei 已提交
1713
        hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1714 1715
    });
} catch (err) {
L
longwei 已提交
1716
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1717 1718 1719 1720 1721 1722 1723
}
```

### bundleManager.setAbilityEnabled

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

W
wtt1995 已提交
1724
设置指定组件的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1725 1726 1727 1728 1729 1730 1731 1732 1733

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1744
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1745
| -------- | ---------------------------------------|
Z
zhaogan 已提交
1746 1747
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityInfo is not found. |
W
wanghang 已提交
1748 1749 1750 1751

**示例:**

```ts
L
Lotol 已提交
1752
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1753
import hilog from '@ohos.hilog';
W
wanghang 已提交
1754 1755 1756 1757
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1758
    abilityName : "EntryAbility"
W
wanghang 已提交
1759
};
1760
let info;
W
wanghang 已提交
1761 1762 1763

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

        bundleManager.setAbilityEnabled(info, false, err => {
            if (err) {
L
longwei 已提交
1769
                hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1770
            } else {
G
geng-wenguang 已提交
1771
                hilog.info(0x0001, "testTag", "setAbilityEnabled successfully.");
W
wanghang 已提交
1772 1773
            }
        });
1774
    }).catch(err => {
L
longwei 已提交
1775
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1776
    });
1777
} catch (err) {
L
longwei 已提交
1778
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1779 1780 1781 1782 1783 1784 1785
}
```

### bundleManager.setAbilityEnabled

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

W
wtt1995 已提交
1786
设置指定组件的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1787 1788 1789 1790 1791 1792 1793 1794 1795

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

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

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

**参数:**

J
junyi233 已提交
1796
| 参数名    | 类型        | 必填 | 说明                                  |
W
wanghang 已提交
1797
| -------- | ----------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1798 1799
| info     | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 需要被设置的组件。                   |
| isEnabled| boolean     | 是   | 值为true表示使能,值为false表示禁用。 |
W
wanghang 已提交
1800 1801 1802 1803 1804

**返回值:**

| 类型           | 说明                              |
| -------------- | --------------------------------- |
Z
zhaogan 已提交
1805
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
W
wanghang 已提交
1806 1807 1808

**错误码:**

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

J
junyi233 已提交
1811
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1812
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1813 1814
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityInfo is not found. |
W
wanghang 已提交
1815 1816 1817 1818

**示例:**

```ts
L
Lotol 已提交
1819
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1820
import hilog from '@ohos.hilog';
W
wanghang 已提交
1821 1822 1823 1824
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1825
    abilityName : "EntryAbility"
W
wanghang 已提交
1826
};
1827
let info;
W
wanghang 已提交
1828 1829 1830

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

W
wtt1995 已提交
1834
        bundleManager.setAbilityEnabled(info, false).then(() => {
G
geng-wenguang 已提交
1835
            hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
W
wtt1995 已提交
1836
        }).catch(err => {
L
longwei 已提交
1837
            hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1838
        });
1839
    }).catch(err => {
L
longwei 已提交
1840
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1841
    });
1842
} catch (err) {
L
longwei 已提交
1843
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1844 1845 1846 1847 1848 1849 1850
}
```

### bundleManager.isApplicationEnabled

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

W
wtt1995 已提交
1851
以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1852 1853 1854 1855 1856 1857 1858

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

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

**参数:**

J
junyi233 已提交
1859
| 参数名      | 类型   | 必填 | 说明                       |
W
wanghang 已提交
1860
| ---------- | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
1861 1862
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。 |
W
wanghang 已提交
1863 1864 1865

**错误码:**

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

J
junyi233 已提交
1868
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1869
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1870
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1871 1872 1873 1874

**示例:**

```ts
L
Lotol 已提交
1875
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1876
import hilog from '@ohos.hilog';
W
wanghang 已提交
1877 1878 1879 1880 1881
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName, (err, data) => {
        if (err) {
L
longwei 已提交
1882
            hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1883
        } else {
L
longwei 已提交
1884
            hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1885 1886 1887
        }
    });
} catch (err) {
L
longwei 已提交
1888
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1889 1890 1891 1892 1893 1894 1895
}
```

### bundleManager.isApplicationEnabled

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

W
wtt1995 已提交
1896
以异步的方法获取指定应用的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1897 1898 1899 1900 1901 1902 1903

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

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

**参数:**

J
junyi233 已提交
1904
| 参数名      | 类型   | 必填 | 说明                       |
W
wanghang 已提交
1905
| ---------- | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
1906
| bundleName | string | 是   | 表示应用程序的bundleName。  |
W
wanghang 已提交
1907 1908 1909 1910 1911 1912 1913 1914 1915

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1918
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1919
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1920
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1921 1922 1923 1924

**示例:**

```ts
L
Lotol 已提交
1925
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1926
import hilog from '@ohos.hilog';
W
wanghang 已提交
1927 1928 1929 1930
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName).then((data) => {
L
longwei 已提交
1931
        hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', JSON.stringify(data));
1932
    }).catch(err => {
L
longwei 已提交
1933
        hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1934
    });
1935
} catch (err) {
L
longwei 已提交
1936
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1937 1938 1939 1940 1941 1942 1943
}
```

### bundleManager.isAbilityEnabled

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

W
wtt1995 已提交
1944
以异步的方法获取指定组件的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1945 1946 1947 1948 1949 1950 1951

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1961
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1962
| -------- | --------------------------------------- |
Z
zhaogan 已提交
1963 1964
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityName is not found. |
W
wanghang 已提交
1965 1966 1967 1968

**示例:**

```ts
L
Lotol 已提交
1969
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1970
import hilog from '@ohos.hilog';
W
wanghang 已提交
1971 1972 1973 1974
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
1975
    abilityName : "EntryAbility"
W
wanghang 已提交
1976
};
1977
let info;
W
wanghang 已提交
1978 1979 1980

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

        bundleManager.isAbilityEnabled(info, (err, data) => {
            if (err) {
L
longwei 已提交
1986
                hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s', err.message);
W
wanghang 已提交
1987
            } else {
L
longwei 已提交
1988
                hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
1989 1990
            }
        });
1991
    }).catch(err => {
L
longwei 已提交
1992
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1993
    });
1994
} catch (err) {
L
longwei 已提交
1995
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
1996 1997 1998 1999 2000 2001 2002
}
```

### bundleManager.isAbilityEnabled

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

W
wtt1995 已提交
2003
以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
2004 2005 2006 2007 2008 2009 2010

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

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

**参数:**

J
junyi233 已提交
2011
| 参数名 | 类型        | 必填 | 说明                        |
W
wanghang 已提交
2012
| ---- | ----------- | ---- | --------------------------- |
Z
zhaogan 已提交
2013
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 表示关于检查ability的信息。 |
W
wanghang 已提交
2014 2015 2016 2017 2018 2019 2020 2021 2022

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
2025
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2026
| -------- | --------------------------------------- |
Z
zhaogan 已提交
2027 2028
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityName is not found. |
W
wanghang 已提交
2029 2030 2031 2032

**示例:**

```ts
L
Lotol 已提交
2033
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2034
import hilog from '@ohos.hilog';
W
wanghang 已提交
2035 2036 2037 2038
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
2039
    abilityName : "EntryAbility"
W
wanghang 已提交
2040
};
2041
let info;
W
wanghang 已提交
2042 2043 2044

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

        bundleManager.isAbilityEnabled(info).then((data) => {
L
longwei 已提交
2049
            hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2050
        }).catch(err => {
L
longwei 已提交
2051
            hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2052
        });
2053
    }).catch(err => {
L
longwei 已提交
2054
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2055
    });
2056
} catch (err) {
L
longwei 已提交
2057
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2058 2059 2060 2061 2062 2063 2064
}
```

### bundleManager.getLaunchWantForBundle

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

W
wtt1995 已提交
2065
以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。
W
wanghang 已提交
2066 2067 2068 2069 2070 2071 2072 2073 2074

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

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

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

**参数:**

J
junyi233 已提交
2075
| 参数名     | 类型                 | 必填 | 说明                                                         |
W
wanghang 已提交
2076
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2077 2078 2079
| bundleName | string               | 是   | 表示应用程序的bundleName。                                     |
| userId     | number               | 是   | 表示用户ID。                                                   |
| callback   | AsyncCallback\<Want> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 |
W
wanghang 已提交
2080 2081 2082

**错误码:**

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

J
junyi233 已提交
2085
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2086
| -------- | --------------------------------------|
Z
zhaogan 已提交
2087
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2088
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2089
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2090 2091 2092 2093

**示例:**

```ts
L
Lotol 已提交
2094
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2095
import hilog from '@ohos.hilog';
W
wanghang 已提交
2096 2097 2098 2099 2100 2101
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => {
        if (err) {
L
longwei 已提交
2102
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2103
        } else {
L
longwei 已提交
2104
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2105 2106 2107
        }
    });
} catch (err) {
L
longwei 已提交
2108
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2109 2110 2111 2112 2113 2114 2115
}
```

### bundleManager.getLaunchWantForBundle

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

W
wtt1995 已提交
2116
以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。
W
wanghang 已提交
2117 2118 2119 2120 2121 2122 2123 2124 2125

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
2135
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2136
| -------- | --------------------------------------|
Z
zhaogan 已提交
2137
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2138
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2139
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2140 2141 2142 2143

**示例:**

```ts
L
Lotol 已提交
2144
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2145
import hilog from '@ohos.hilog';
W
wanghang 已提交
2146 2147 2148 2149 2150
let bundleName = 'com.example.myapplication';

try {
    bundleManager.getLaunchWantForBundle(bundleName, (err, data) => {
        if (err) {
L
longwei 已提交
2151
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2152
        } else {
L
longwei 已提交
2153
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2154 2155 2156
        }
    });
} catch (err) {
L
longwei 已提交
2157
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s', err.message);
W
wanghang 已提交
2158 2159 2160 2161 2162 2163 2164
}
```

### bundleManager.getLaunchWantForBundle

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

W
wtt1995 已提交
2165
以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用Promise形式返回结果。
W
wanghang 已提交
2166 2167 2168 2169 2170 2171 2172 2173 2174

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

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

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

**参数:**

Z
zhaogan 已提交
2175 2176 2177 2178
| 参数名     | 类型   | 必填 | 说明                       |
| ---------- | ------ | ---- | ------------------------- |
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| userId     | number | 否   | 表示用户ID。               |
W
wanghang 已提交
2179 2180 2181 2182 2183

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
Z
zhaogan 已提交
2184
| Promise\<Want> | Promise对象,返回Want对象。 |
W
wanghang 已提交
2185 2186 2187

**错误码:**

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

J
junyi233 已提交
2190
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2191
| -------- | --------------------------------------|
Z
zhaogan 已提交
2192
| 17700001 | The specified bundleName is not found. |
2193
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2194
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2195 2196 2197 2198

**示例:**

```ts
L
Lotol 已提交
2199
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2200
import hilog from '@ohos.hilog';
W
wanghang 已提交
2201 2202 2203 2204 2205
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => {
L
longwei 已提交
2206
        hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', JSON.stringify(data));
2207
    }).catch(err => {
L
longwei 已提交
2208
        hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2209
    });
2210
} catch (err) {
L
longwei 已提交
2211
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224
}
```

### bundleManager.getProfileByAbility

getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback<Array\<string>>): void;

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

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

**参数:**

J
junyi233 已提交
2225
| 参数名       | 类型                          | 必填 | 说明                                                         |
W
wanghang 已提交
2226
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2227 2228 2229 2230
| moduleName   | string                        | 是   | 表示应用程序的moduleName。                                     |
| abilityName  | string                        | 是   | 表示应用程序的abilityName。                                    |
| metadataName | string                        | 是   | 表示应用程序的metadataName。                                  |
| callback     | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
W
wanghang 已提交
2231 2232 2233

**错误码:**

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

J
junyi233 已提交
2236
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2237
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2238 2239
| 17700002 | The specified moduleName is not existed.                      |
| 17700003 | The specified abilityName is not existed.                     |
2240
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2241 2242
| 17700026 | The specified bundle is disabled.                             |
| 17700029 | The specified ability is disabled.                            |
W
wanghang 已提交
2243 2244 2245 2246

**示例:**

```ts
L
Lotol 已提交
2247
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2248
import hilog from '@ohos.hilog';
W
wanghang 已提交
2249
let moduleName = 'entry';
2250
let abilityName = 'EntryAbility';
W
wanghang 已提交
2251 2252 2253 2254 2255
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
        if (err) {
L
longwei 已提交
2256
            hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2257
        } else {
L
longwei 已提交
2258
            hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2259 2260 2261
        }
    });
} catch (err) {
L
longwei 已提交
2262
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275
}
```

### bundleManager.getProfileByAbility

getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise<Array\<string>>;

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

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

**参数:**

J
junyi233 已提交
2276
| 参数名       | 类型   | 必填 | 说明                       |
W
wanghang 已提交
2277
| ------------ | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
2278 2279 2280
| moduleName   | string | 是   | 表示应用程序的moduleName。   |
| abilityName  | string | 是   | 表示应用程序的abilityName。  |
| metadataName | string | 否   | 表示应用程序的metadataName。 |
W
wanghang 已提交
2281 2282 2283 2284 2285

**返回值:**

| 类型                    | 说明                            |
| ----------------------- | ------------------------------- |
Z
zhaogan 已提交
2286
| Promise<Array\<string>> | Promise对象,返回Array\<string>。 |
W
wanghang 已提交
2287 2288 2289

**错误码:**

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

J
junyi233 已提交
2292
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2293
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2294 2295
| 17700002 | The specified moduleName is not existed.                      |
| 17700003 | The specified abilityName is not existed.                     |
2296
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2297 2298
| 17700026 | The specified bundle is disabled.                             |
| 17700029 | The specified ability is disabled.                            |
W
wanghang 已提交
2299 2300 2301 2302

**示例:**

```ts
L
Lotol 已提交
2303
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2304
import hilog from '@ohos.hilog';
W
wanghang 已提交
2305
let moduleName = 'entry';
2306
let abilityName = 'EntryAbility';
W
wanghang 已提交
2307 2308 2309

try {
    bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
L
longwei 已提交
2310
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
2311
    }).catch(err => {
L
longwei 已提交
2312
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2313
    });
2314
} catch (err) {
L
longwei 已提交
2315
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2316
}
Z
zhaogan 已提交
2317
```
W
wanghang 已提交
2318

Z
zhaogan 已提交
2319
```ts
L
Lotol 已提交
2320
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2321
import hilog from '@ohos.hilog';
Z
zhaogan 已提交
2322
let moduleName = 'entry';
2323
let abilityName = 'EntryAbility';
Z
zhaogan 已提交
2324
let metadataName = 'com.example.myapplication.metadata';
W
wanghang 已提交
2325
try {
Z
zhaogan 已提交
2326
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
L
longwei 已提交
2327
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', JSON.stringify(data));
2328
    }).catch(err => {
L
longwei 已提交
2329
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2330
    });
2331
} catch (err) {
L
longwei 已提交
2332
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345
}
```

### bundleManager.getProfileByExtensionAbility

getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback<Array\<string>>): void;

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

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

**参数:**

2346
| 参数名                 | 类型                          | 必填 | 说明                                                         |
W
wanghang 已提交
2347
| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ |
J
junyi233 已提交
2348 2349 2350
| moduleName           | string                        | 是   | 表示应用程序的moduleName。                                   |
| extensionAbilityName | string                        | 是   | 表示应用程序的extensionAbilityName。                         |
| metadataName         | string                        | 是   | 表示应用程序的metadataName。                                 |
Z
zhaogan 已提交
2351
| callback             | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
W
wanghang 已提交
2352 2353 2354

**错误码:**

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

J
junyi233 已提交
2357
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2358
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2359
| 17700002 | The specified moduleName is not existed.                      |
J
junyi233 已提交
2360
| 17700003 | The specified extensionAbilityName not existed.            |
2361
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2362
| 17700026 | The specified bundle is disabled.                             |
W
wanghang 已提交
2363 2364 2365 2366

**示例:**

```ts
L
Lotol 已提交
2367
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2368
import hilog from '@ohos.hilog';
W
wanghang 已提交
2369 2370 2371 2372 2373 2374 2375
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 已提交
2376
            hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
W
wanghang 已提交
2377
        } else {
L
longwei 已提交
2378
            hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2379 2380 2381
        }
    });
} catch (err) {
L
longwei 已提交
2382
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s', err.message);
W
wanghang 已提交
2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395
}
```

### bundleManager.getProfileByExtensionAbility

getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise<Array\<string>>;

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

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

**参数:**

2396
| 参数名                 | 类型   | 必填 | 说明                               |
J
junyi233 已提交
2397
| -------------------- | ------ | ---- | ---------------------------------- |
Z
zhaogan 已提交
2398 2399 2400
| moduleName           | string | 是   | 表示应用程序的moduleName。           |
| extensionAbilityName | string | 是   | 表示应用程序的extensionAbilityName。 |
| metadataName         | string | 否   | 表示应用程序的metadataName。         |
W
wanghang 已提交
2401 2402 2403 2404 2405

**返回值:**

| 类型                    | 说明                                |
| ----------------------- | ----------------------------------- |
Z
zhaogan 已提交
2406
| Promise<Array\<string>> | Promise对象,返回Array\<string>对象。 |
W
wanghang 已提交
2407 2408 2409

**错误码:**

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

J
junyi233 已提交
2412
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2413
| -------- | ------------------------------------------------------------ |
L
Lotol 已提交
2414
| 17700002 | The specified moduleName is not existed.                      |
J
junyi233 已提交
2415
| 17700003 | The specified extensionAbilityName not existed.            |
2416
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2417
| 17700026 | The specified bundle is disabled.                             |
W
wanghang 已提交
2418 2419 2420 2421

**示例:**

```ts
L
Lotol 已提交
2422
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2423
import hilog from '@ohos.hilog';
W
wanghang 已提交
2424 2425 2426 2427 2428 2429
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
L
longwei 已提交
2430
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
2431
    }).catch(err => {
L
longwei 已提交
2432
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2433
    });
2434
} catch (err) {
L
longwei 已提交
2435
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2436 2437 2438 2439
}

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => {
L
longwei 已提交
2440
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', JSON.stringify(data));
2441
    }).catch(err => {
L
longwei 已提交
2442
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2443
    });
2444
} catch (err) {
L
longwei 已提交
2445
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2446 2447 2448 2449 2450 2451 2452
}
```

### bundleManager.getPermissionDef

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

W
wtt1995 已提交
2453
以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。
W
wanghang 已提交
2454 2455 2456 2457 2458 2459 2460 2461 2462

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
2472 2473
| 错误码ID | 错误信息                              |
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2474
| 17700006 | The specified permission is not found. |
W
wanghang 已提交
2475 2476 2477 2478

**示例:**

```ts
L
Lotol 已提交
2479
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2480
import hilog from '@ohos.hilog';
W
wanghang 已提交
2481 2482 2483 2484
let permission = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permission, (err, data) => {
        if (err) {
L
longwei 已提交
2485
            hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message);
W
wanghang 已提交
2486
        } else {
L
longwei 已提交
2487
            hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2488 2489 2490
        }
    });
} catch (err) {
L
longwei 已提交
2491
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s', err.message);
W
wanghang 已提交
2492 2493 2494 2495 2496 2497 2498
}
```

### bundleManager.getPermissionDef

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

W
wtt1995 已提交
2499
以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用Promise形式返回结果。
W
wanghang 已提交
2500 2501 2502 2503 2504 2505 2506 2507 2508

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

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

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

**参数:**

2509
| 参数名           | 类型   | 必填 | 说明           |
J
junyi233 已提交
2510
| -------------- | ------ | ---- | -------------- |
Z
zhaogan 已提交
2511
| permissionName | string | 是   | 表示权限参数名。 |
W
wanghang 已提交
2512 2513 2514 2515 2516

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
2523 2524
| 错误码ID | 错误信息                              |
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2525
| 17700006 | The specified permission is not found. |
W
wanghang 已提交
2526 2527 2528 2529

**示例:**

```ts
L
Lotol 已提交
2530
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2531
import hilog from '@ohos.hilog';
W
wanghang 已提交
2532 2533 2534
let permissionName = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permissionName).then((data) => {
L
longwei 已提交
2535
        hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', JSON.stringify(data));
2536
    }).catch(err => {
L
longwei 已提交
2537
        hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2538
    });
2539
} catch (err) {
L
longwei 已提交
2540
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
}
```

### 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 已提交
2558
| 参数名      | 类型                   | 必填 | 说明                                                         |
W
wanghang 已提交
2559
| ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2560 2561 2562 2563
| bundleName  | string                 | 是   | 表示应用程序的bundleName。                                     |
| moduleName  | string                 | 是   | 表示应用程序的moduleName。                                     |
| abilityName | string                 | 是   | 表示应用程序的abilityName。                                    |
| callback    | AsyncCallback\<string> | 是   | 回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。 |
W
wanghang 已提交
2564 2565 2566

**错误码:**

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

J
junyi233 已提交
2569 2570
| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2571 2572 2573 2574 2575
| 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 已提交
2576 2577 2578 2579

**示例:**

```ts
L
Lotol 已提交
2580
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2581
import hilog from '@ohos.hilog';
W
wanghang 已提交
2582 2583
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
2584
let abilityName = 'EntryAbility';
W
wanghang 已提交
2585 2586 2587 2588

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => {
        if (err) {
L
longwei 已提交
2589
            hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message);
W
wanghang 已提交
2590
        } else {
L
longwei 已提交
2591
            hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2592 2593 2594
        }
    });
} catch (err) {
L
longwei 已提交
2595
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s', err.message);
W
wanghang 已提交
2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612
}
```

### 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 已提交
2613
| 参数名      | 类型   | 必填 | 说明                      |
W
wanghang 已提交
2614
| ----------- | ------ | ---- | ------------------------- |
Z
zhaogan 已提交
2615 2616 2617
| bundleName  | string | 是   | 表示应用程序的bundleName。  |
| moduleName  | string | 是   | 表示应用程序的moduleName。  |
| abilityName | string | 是   | 表示应用程序的abilityName。 |
W
wanghang 已提交
2618 2619 2620 2621 2622

**返回值:**

| 类型             | 说明                                |
| ---------------- | ----------------------------------- |
Z
zhaogan 已提交
2623
| Promise\<string> | Promise对象,返回指定组件的Lablel值。 |
W
wanghang 已提交
2624 2625 2626

**错误码:**

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

J
junyi233 已提交
2629
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2630
| -------- | --------------------------------------- |
Z
zhaogan 已提交
2631 2632 2633 2634 2635
| 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 已提交
2636 2637 2638 2639

**示例:**

```ts
L
Lotol 已提交
2640
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2641
import hilog from '@ohos.hilog';
W
wanghang 已提交
2642 2643
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
2644
let abilityName = 'EntryAbility';
W
wanghang 已提交
2645 2646 2647

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => {
L
longwei 已提交
2648
        hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', JSON.stringify(data));
2649
    }).catch(err => {
L
longwei 已提交
2650
        hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2651
    });
2652
} catch (err) {
L
longwei 已提交
2653
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s', err.message);
W
wanghang 已提交
2654 2655 2656 2657 2658 2659 2660
}
```


### bundleManager.getApplicationInfoSync

getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);
L
Lotol 已提交
2661
getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);
W
wanghang 已提交
2662

W
wtt1995 已提交
2663
以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。
W
wanghang 已提交
2664 2665 2666 2667 2668

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

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

W
wtt1995 已提交
2669
**系统能力:** SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
2670 2671 2672

**参数:**

J
junyi233 已提交
2673
| 参数名       | 类型   | 必填 | 说明                                                       |
W
wanghang 已提交
2674
| ----------- | ------ | ---- | ----------------------------------------------------------|
Z
zhaogan 已提交
2675 2676
| bundleName  | string | 是   | 表示应用程序的bundleName。                                  |
| applicationFlags | [number](#applicationflag) | 是   | 表示用于指定将返回的ApplicationInfo对象中包含的信息。       |
L
Lotol 已提交
2677
| userId      | number | 是   | 表示用户ID。                                         |
W
wanghang 已提交
2678 2679 2680 2681 2682

**返回值:**

| 类型            | 说明                      |
| --------------- | ------------------------- |
Z
zhaogan 已提交
2683
| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 |
W
wanghang 已提交
2684 2685 2686

**错误码:**

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

J
junyi233 已提交
2689
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2690
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2691
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2692
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2693
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2694 2695 2696 2697

**示例:**

```ts
L
Lotol 已提交
2698
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2699
import hilog from '@ohos.hilog';
W
wanghang 已提交
2700 2701 2702 2703 2704 2705
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 已提交
2706
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2707
} catch (err) {
L
longwei 已提交
2708
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2709 2710 2711 2712
}
```

```ts
L
Lotol 已提交
2713
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2714
import hilog from '@ohos.hilog';
W
wanghang 已提交
2715 2716 2717 2718 2719
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags);
L
longwei 已提交
2720
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2721
} catch (err) {
L
longwei 已提交
2722
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2723 2724 2725 2726 2727 2728
}
```

### bundleManager.getBundleInfoSync

getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md);
L
Lotol 已提交
2729
getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md);
W
wanghang 已提交
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740

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

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

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

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

**参数:**

J
junyi233 已提交
2741
| 参数名       | 类型   | 必填 | 说明                                                     |
W
wanghang 已提交
2742
| ----------- | ------ | ---- | -------------------------------------------------------- |
Z
zhaogan 已提交
2743 2744
| bundleName  | string | 是   | 表示应用程序的bundleName。                                 |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 |
Z
zhoagan 已提交
2745
| userId      | number | 否   | 表示用户ID。                                             |
W
wanghang 已提交
2746 2747 2748 2749 2750

**返回值:**

| 类型       | 说明                 |
| ---------- | -------------------- |
Z
zhaogan 已提交
2751
| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 |
W
wanghang 已提交
2752 2753 2754

**错误码:**

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

J
junyi233 已提交
2757
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2758
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2759
| 17700001 | The specified bundleName is not found. |
2760
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2761
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2762 2763 2764 2765

**示例:**

```ts
L
Lotol 已提交
2766
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2767
import hilog from '@ohos.hilog';
W
wanghang 已提交
2768 2769 2770 2771 2772 2773
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 已提交
2774
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2775
} catch (err) {
L
longwei 已提交
2776
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2777 2778 2779 2780
}
```

```ts
L
Lotol 已提交
2781
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2782
import hilog from '@ohos.hilog';
W
wanghang 已提交
2783 2784 2785
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
try {
Z
zhaogan 已提交
2786
    let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags);
L
longwei 已提交
2787
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', JSON.stringify(data));
W
wanghang 已提交
2788
} catch (err) {
L
longwei 已提交
2789
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s', err.message);
W
wanghang 已提交
2790
}
Z
zhongjianfei 已提交
2791
```