js-apis-bundleManager.md 124.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));
W
wanghang 已提交
219
    }).catch(error => {
G
geng-wenguang 已提交
220
        hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', error.message);
W
wanghang 已提交
221 222
    });
} catch (error) {
G
geng-wenguang 已提交
223
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', error.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) {
G
geng-wenguang 已提交
252
            hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', error.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) {
G
geng-wenguang 已提交
258
    hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', error.message);
W
wanghang 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
}
```

### bundleManager.getBundleInfo

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

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

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

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

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

**参数:**

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

**错误码:**

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

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

**示例:**

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

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

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
327
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message);
W
wanghang 已提交
328
        } else {
G
geng-wenguang 已提交
329
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
330 331 332
        }
    });
} catch (err) {
G
geng-wenguang 已提交
333
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message);
W
wanghang 已提交
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
}
```

### bundleManager.getBundleInfo

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

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

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

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

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

**参数:**

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

**错误码:**

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

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

**示例:**

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

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
379
            hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message);
W
wanghang 已提交
380
        } else {
G
geng-wenguang 已提交
381
            hilog.info(0x0000, 'testTag', 'getBundleInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
382 383 384
        }
    });
} catch (err) {
G
geng-wenguang 已提交
385
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed: %{public}s' + err.message);
W
wanghang 已提交
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
}
```

### bundleManager.getBundleInfo

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

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

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

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

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

**参数:**

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

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
419
| 错误码ID | 错误信息                            |
W
wanghang 已提交
420
| -------- | --------------------------------------|
Z
zhaogan 已提交
421
| 17700001 | The specified bundleName is not found. |
422
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
423
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
424 425 426 427

**示例:**

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

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => {
G
geng-wenguang 已提交
437
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
438
    }).catch(error => {
G
geng-wenguang 已提交
439
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
440 441
    });
} catch (error) {
G
geng-wenguang 已提交
442
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
443 444 445 446
}
```

```ts
L
Lotol 已提交
447
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
448
import hilog from '@ohos.hilog';
W
wanghang 已提交
449 450 451 452 453
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => {
G
geng-wenguang 已提交
454
        hilog.info(0x0000, 'testTag', 'getBundleInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
455
    }).catch(error => {
G
geng-wenguang 已提交
456
        hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
457 458
    });
} catch (error) {
G
geng-wenguang 已提交
459
    hilog.error(0x0000, 'testTag', 'getBundleInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
}

```

### bundleManager.getApplicationInfo

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

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

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
489
| 错误码ID | 错误信息                             |
W
wanghang 已提交
490
| -------- | --------------------------------------|
Z
zhaogan 已提交
491
| 17700001 | The specified bundleName is not found. |
492
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
493
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
494

495
**示例:** 
W
wanghang 已提交
496 497

```ts
L
Lotol 已提交
498
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
499
import hilog from '@ohos.hilog';
W
wanghang 已提交
500 501 502 503 504 505 506
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) {
G
geng-wenguang 已提交
507
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message);
W
wanghang 已提交
508
        } else {
G
geng-wenguang 已提交
509
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
510 511 512
        }
    });
} catch (err) {
G
geng-wenguang 已提交
513
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message);
W
wanghang 已提交
514 515 516 517 518 519 520 521 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形式返回结果。

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
541
| 错误码ID | 错误信息                             |
W
wanghang 已提交
542
| -------- | --------------------------------------|
Z
zhaogan 已提交
543
| 17700001 | The specified bundleName is not found. |
544
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
545
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
546 547 548 549

**示例:**

```ts
L
Lotol 已提交
550
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
551
import hilog from '@ohos.hilog';
W
wanghang 已提交
552
let bundleName = 'com.example.myapplication';
Z
zhaogan 已提交
553
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
W
wanghang 已提交
554 555 556 557

try {
    bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
558
            hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message);
W
wanghang 已提交
559
        } else {
G
geng-wenguang 已提交
560
            hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
561 562 563
        }
    });
} catch (err) {
G
geng-wenguang 已提交
564
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed: %{public}s' + err.message);
W
wanghang 已提交
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
}
```

### bundleManager.getApplicationInfo

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

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

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

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

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

**参数:**

J
junyi233 已提交
582
| 参数名    | 类型   | 必填 | 说明                       |
W
wanghang 已提交
583
| ---------- | ------ | ---- | ---------------------------- |
584
| bundleName | string | 是   | 表示要查询的应用Bundle名称。 |
Z
zhaogan 已提交
585 586
| appFlags   | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。    |
| userId     | number | 否   | 表示用户ID。 |
W
wanghang 已提交
587 588 589 590 591

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
598
| 错误码ID | 错误信息                             |
W
wanghang 已提交
599
| -------- | ------------------------------------- |
Z
zhaogan 已提交
600
| 17700001 | The specified bundleName is not found. |
601
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
602
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
603 604 605 606

**示例:**

```ts
L
Lotol 已提交
607
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
608
import hilog from '@ohos.hilog';
W
wanghang 已提交
609 610 611 612 613 614
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) => {
G
geng-wenguang 已提交
615
        hilog.info(0x0000, 'testTag', 'getApplicationInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
616
    }).catch(error => {
G
geng-wenguang 已提交
617
        hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
618 619
    });
} catch (error) {
G
geng-wenguang 已提交
620
    hilog.error(0x0000, 'testTag', 'getApplicationInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
621 622 623 624 625 626 627
}
```

### bundleManager.getAllBundleInfo

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

W
wtt1995 已提交
628
以异步方法根据给定的bundleFlags和userId获取系统中所有的BundleInfo,使用callback形式返回结果。
W
wanghang 已提交
629 630 631 632 633 634 635 636 637

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
648
| 错误码ID | 错误信息                         |
W
wanghang 已提交
649
| -------- | --------------------------------- |
650
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
651 652 653 654

**示例:**

```ts
L
Lotol 已提交
655
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
656
import hilog from '@ohos.hilog';
W
wanghang 已提交
657 658 659 660 661 662
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;

try {
    bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
663
            hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s' + err.message);
W
wanghang 已提交
664
        } else {
G
geng-wenguang 已提交
665
            hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
666 667 668
        }
    });
} catch (err) {
G
geng-wenguang 已提交
669
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed: %{public}s' + err.message);
W
wanghang 已提交
670 671 672 673 674 675 676
}
```

### bundleManager.getAllBundleInfo

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

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

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

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

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

**参数:**

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

**错误码:**

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

696 697 698 699
| 错误码ID | 错误信息                         |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |

W
wanghang 已提交
700 701 702
**示例:**

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

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

### bundleManager.getAllBundleInfo

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

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

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

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

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

**参数:**

J
junyi233 已提交
734
| 参数名     | 类型   | 必填 | 说明                                             |
W
wanghang 已提交
735
| ----------- | ------ | ---- | -------------------------------------------------- |
Z
zhaogan 已提交
736 737
| bundleFlags | [number](#bundleflag) | 是   | 指定返回的BundleInfo所包含的信息。                   |
| userId      | number | 否   | 表示用户ID。                         |
W
wanghang 已提交
738 739 740 741 742

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
749
| 错误码ID | 错误信息                         |
W
wanghang 已提交
750
| -------- | ---------------------------------- |
751
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
752 753 754 755

**示例:**

```ts
L
Lotol 已提交
756
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
757
import hilog from '@ohos.hilog';
W
wanghang 已提交
758 759 760 761
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getAllBundleInfo(bundleFlags).then((data) => {
G
geng-wenguang 已提交
762
        hilog.info(0x0000, 'testTag', 'getAllBundleInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
763
    }).catch(error => {
G
geng-wenguang 已提交
764
        hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
765 766
    });
} catch (error) {
G
geng-wenguang 已提交
767
    hilog.error(0x0000, 'testTag', 'getAllBundleInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
768 769 770 771 772 773 774
}
```

### bundleManager.getAllApplicationInfo

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

W
wtt1995 已提交
775
以异步方法根据给定的appFlags和userId获取系统中所有的ApplicationInfo,使用callback形式返回结果。
W
wanghang 已提交
776 777 778 779 780 781 782 783 784

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

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

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

**参数:**

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

**错误码:**

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

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

**示例:**

```ts
L
Lotol 已提交
802
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
803
import hilog from '@ohos.hilog';
W
wanghang 已提交
804 805 806 807 808 809
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
810
            hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s' + err.message);
W
wanghang 已提交
811
        } else {
G
geng-wenguang 已提交
812
            hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
813 814 815
        }
    });
} catch (err) {
G
geng-wenguang 已提交
816
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed: %{public}s' + err.message);
W
wanghang 已提交
817 818 819 820 821 822 823
}
```

### bundleManager.getAllApplicationInfo

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

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

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

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

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

**参数:**

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

**错误码:**

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

843 844 845 846
| 错误码ID | 错误信息                         |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |

W
wanghang 已提交
847 848 849
**示例:**

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

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

### bundleManager.getAllApplicationInfo

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

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

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

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

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

**参数:**

J
junyi233 已提交
881
| 参数名  | 类型   | 必填 | 说明                                                      |
W
wanghang 已提交
882
| -------- | ------ | ---- | ---------------------------------------------------------- |
Z
zhaogan 已提交
883 884
| appFlags | [number](#applicationflag) | 是   | 指定返回的ApplicationInfo所包含的信息。                       |
| userId   | number | 否   | 表示用户ID。                                  |
W
wanghang 已提交
885 886 887 888 889

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
896
| 错误码ID | 错误信息                         |
W
wanghang 已提交
897
| -------- | ---------------------------------- |
898
| 17700004 | The specified user ID is not found. |
W
wanghang 已提交
899 900 901 902

**示例:**

```ts
L
Lotol 已提交
903
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
904
import hilog from '@ohos.hilog';
W
wanghang 已提交
905 906 907 908
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    bundleManager.getAllApplicationInfo(appFlags).then((data) => {
G
geng-wenguang 已提交
909
        hilog.info(0x0000, 'testTag', 'getAllApplicationInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
910
    }).catch(error => {
G
geng-wenguang 已提交
911
        hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
912 913
    });
} catch (error) {
G
geng-wenguang 已提交
914
    hilog.error(0x0000, 'testTag', 'getAllApplicationInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
}

```

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

**错误码:**

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

J
junyi233 已提交
944
| 错误码ID | 错误信息                             |
W
wanghang 已提交
945
| -------- | -------------------------------------- |
Z
zhaogan 已提交
946 947 948 949 950
| 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 已提交
951 952 953 954

**示例:**

```ts
L
Lotol 已提交
955
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
956
import hilog from '@ohos.hilog';
W
wanghang 已提交
957 958 959 960 961 962 963 964 965 966
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
967
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
968
        } else {
G
geng-wenguang 已提交
969
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
970 971 972
        }
    });
} catch (err) {
G
geng-wenguang 已提交
973
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
}
```

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

**错误码:**

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

J
junyi233 已提交
1001
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1002
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1003 1004
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified ability is not found.    |
1005
| 17700004 | The specified userId is invalid.       |
Z
zhaogan 已提交
1006 1007
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
1008 1009 1010 1011

**示例:**

```ts
L
Lotol 已提交
1012
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1013
import hilog from '@ohos.hilog';
W
wanghang 已提交
1014 1015 1016 1017 1018 1019 1020 1021 1022
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
1023
            hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
1024
        } else {
G
geng-wenguang 已提交
1025
            hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1026 1027 1028
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1029
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
}
```

### 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 已提交
1047
| 参数名      | 类型   | 必填 | 说明                                                  |
W
wanghang 已提交
1048
| ------------ | ------ | ---- | ------------------------------------------------------- |
1049
| want         | Want   | 是   | 表示包含要查询的应用Bundle名称的Want。                 |
Z
zhaogan 已提交
1050 1051
| abilityFlags | [number](#abilityflag) | 是   | 表示指定返回的AbilityInfo所包含的信息。 |
| userId       | number | 否   | 表示用户ID。                               |
W
wanghang 已提交
1052 1053 1054 1055 1056

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1063
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1064
| -------- | ------------------------------------- |
Z
zhaogan 已提交
1065
| 17700001 | The specified bundleName is not found. |
1066
| 17700003 | The specified extensionAbility is not found.    |
Z
zhaogan 已提交
1067 1068 1069
| 17700004 | The specified userId is invalid.       |
| 17700026 | The specified bundle is disabled.      |
| 17700029 | The specified ability is disabled.     |
W
wanghang 已提交
1070 1071 1072 1073

**示例:**

```ts
L
Lotol 已提交
1074
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1075
import hilog from '@ohos.hilog';
W
wanghang 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => {
G
geng-wenguang 已提交
1085
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1086
    }).catch(error => {
G
geng-wenguang 已提交
1087
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1088 1089
    });
} catch (error) {
G
geng-wenguang 已提交
1090
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1091 1092 1093 1094
}
```

```ts
L
Lotol 已提交
1095
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1096
import hilog from '@ohos.hilog';
W
wanghang 已提交
1097 1098 1099 1100 1101 1102 1103 1104
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => {
G
geng-wenguang 已提交
1105
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1106
    }).catch(error => {
G
geng-wenguang 已提交
1107
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1108 1109
    })
} catch (error) {
G
geng-wenguang 已提交
1110
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
}
```

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

**错误码:**

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

J
junyi233 已提交
1140 1141
| 错误码ID | 错误信息                                    |
| -------- | ------------------------------------------- |
Z
zhaogan 已提交
1142 1143 1144 1145
| 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 已提交
1146 1147 1148 1149

**示例:**

```ts
L
Lotol 已提交
1150
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1151
import hilog from '@ohos.hilog';
W
wanghang 已提交
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
1163
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
1164
        } else {
G
geng-wenguang 已提交
1165
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1166 1167 1168
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1169
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
}
```

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

**错误码:**

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

J
junyi233 已提交
1198 1199
| 错误码ID | 错误信息                                     |
| -------- | -------------------------------------------- |
Z
zhaogan 已提交
1200 1201
| 17700001 | The specified bundleName is not found.       |
| 17700003 | The specified extensionAbility is not found. |
1202
| 17700004 | The specified userId is invalid.       |
Z
zhaogan 已提交
1203
| 17700026 | The specified bundle is disabled.            |
W
wanghang 已提交
1204 1205 1206 1207

**示例:**

```ts
L
Lotol 已提交
1208
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1209
import hilog from '@ohos.hilog';
W
wanghang 已提交
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
1220
            hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
1221
        } else {
G
geng-wenguang 已提交
1222
            hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1223 1224 1225
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1226
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed: %{public}s' + err.message);
W
wanghang 已提交
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
}
```

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

**参数:**

1244 1245 1246
| 参数名                | 类型                                          | 必填 | 说明                                                      |
| --------------------- | --------------------------------------------- | ---- | --------------------------------------------------------- |
| want                  | Want                                          | 是   | 表示包含要查询的应用Bundle名称的Want。                    |
Z
zhaogan 已提交
1247 1248 1249
| extensionAbilityType  | [ExtensionAbilityType](#extensionabilitytype) | 是   | 标识extensionAbility的类型。                              |
| extensionAbilityFlags | [number](#extensionabilityflag)               | 是   | 表示用于指定将返回的ExtensionInfo对象中包含的信息的标志。 |
| userId                | number                                        | 否   | 表示用户ID。                                              |
W
wanghang 已提交
1250 1251 1252 1253 1254

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1261
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1262
| -------- | --------------------------------------|
Z
zhaogan 已提交
1263 1264 1265 1266
| 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 已提交
1267 1268 1269 1270

**示例:**

```ts
L
Lotol 已提交
1271
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1272
import hilog from '@ohos.hilog';
W
wanghang 已提交
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283

let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => {
G
geng-wenguang 已提交
1284
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1285
    }).catch(error => {
G
geng-wenguang 已提交
1286
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1287 1288
    });
} catch (error) {
G
geng-wenguang 已提交
1289
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1290 1291 1292 1293
}
```

```ts
L
Lotol 已提交
1294
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1295
import hilog from '@ohos.hilog';
W
wanghang 已提交
1296 1297 1298 1299 1300 1301 1302 1303 1304
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};

try {
    bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => {
G
geng-wenguang 已提交
1305
        hilog.info(0x0000, 'testTag', 'queryExtensionAbilityInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1306
    }).catch(error => {
G
geng-wenguang 已提交
1307
        hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1308 1309
    })
} catch (error) {
G
geng-wenguang 已提交
1310
    hilog.error(0x0000, 'testTag', 'queryExtensionAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1311 1312 1313 1314 1315 1316 1317
}
```

### bundleManager.getBundleNameByUid

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

W
wtt1995 已提交
1318
以异步方法根据给定的uid获取对应的bundleName,使用callback形式返回结果。
W
wanghang 已提交
1319 1320 1321 1322 1323 1324 1325 1326 1327

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1337
| 错误码ID | 错误信息            |
W
wanghang 已提交
1338
| -------- | --------------------- |
Z
zhaogan 已提交
1339
| 17700021 | The uid is not found. |
W
wanghang 已提交
1340 1341 1342 1343

**示例:**

```ts
L
Lotol 已提交
1344
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1345
import hilog from '@ohos.hilog';
W
wanghang 已提交
1346 1347 1348 1349
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
1350
            hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s' + err.message);
W
wanghang 已提交
1351
        } else {
G
geng-wenguang 已提交
1352
            hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1353 1354 1355
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1356
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed: %{public}s' + err.message);
W
wanghang 已提交
1357 1358 1359 1360 1361 1362 1363
}
```

### bundleManager.getBundleNameByUid

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

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

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

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

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

**参数:**

J
junyi233 已提交
1374
| 参数名 | 类型   | 必填 | 说明                |
W
wanghang 已提交
1375
| ---- | ------ | ---- | ------------------ |
Z
zhaogan 已提交
1376
| uid  | number | 是   | 表示应用程序的UID。 |
W
wanghang 已提交
1377 1378 1379 1380 1381

**返回值:**

| 类型             | 说明                        |
| ---------------- | --------------------------- |
Z
zhaogan 已提交
1382
| Promise\<string> | Promise对象,返回bundleName。 |
W
wanghang 已提交
1383 1384 1385

**错误码:**

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

J
junyi233 已提交
1388
| 错误码ID | 错误信息            |
W
wanghang 已提交
1389
| -------- | ---------------------|
Z
zhaogan 已提交
1390
| 17700021 | The uid is not found. |
W
wanghang 已提交
1391 1392 1393 1394

**示例:**

```ts
L
Lotol 已提交
1395
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1396
import hilog from '@ohos.hilog';
W
wanghang 已提交
1397 1398 1399
let uid = 20010005;
try {
    bundleManager.getBundleNameByUid(uid).then((data) => {
G
geng-wenguang 已提交
1400
        hilog.info(0x0000, 'testTag', 'getBundleNameByUid successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1401
    }).catch(error => {
G
geng-wenguang 已提交
1402
        hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1403 1404
    });
} catch (error) {
G
geng-wenguang 已提交
1405
    hilog.error(0x0000, 'testTag', 'getBundleNameByUid failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
}
```

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

**错误码:**

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

J
junyi233 已提交
1433
| 错误码ID | 错误信息                  |
W
wanghang 已提交
1434
| -------- | --------------------------- |
Z
zhaogan 已提交
1435
| 17700022 | The hapFilePath is invalid. |
W
wanghang 已提交
1436 1437 1438 1439

**示例:**

```ts
L
Lotol 已提交
1440
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1441
import hilog from '@ohos.hilog';
W
wanghang 已提交
1442 1443 1444 1445 1446 1447
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
1448
            hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1449
        } else {
G
geng-wenguang 已提交
1450
            hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1451 1452 1453
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1454
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
}
```

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

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1487
| 错误码ID | 错误信息                   |
W
wanghang 已提交
1488
| -------- | -------------------------- |
Z
zhaogan 已提交
1489
| 17700022 | The hapFilePath is invalid. |
W
wanghang 已提交
1490 1491 1492 1493

**示例:**

```ts
L
Lotol 已提交
1494
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1495
import hilog from '@ohos.hilog';
W
wanghang 已提交
1496 1497 1498 1499 1500
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;

try {
    bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => {
G
geng-wenguang 已提交
1501
        hilog.info(0x0000, 'testTag', 'getBundleArchiveInfo successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1502
    }).catch(error => {
G
geng-wenguang 已提交
1503
        hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1504 1505
    });
} catch (error) {
G
geng-wenguang 已提交
1506
    hilog.error(0x0000, 'testTag', 'getBundleArchiveInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1507 1508 1509 1510 1511 1512 1513
}
```

### bundleManager.cleanBundleCacheFiles

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

W
wtt1995 已提交
1514
以异步方法根据给定的bundleName清理BundleCache,使用callback形式返回结果。
W
wanghang 已提交
1515 1516 1517 1518 1519 1520 1521 1522 1523

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1533
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
1534
| -------- | ------------------------------------------------------------ |
Z
zhaogan 已提交
1535
| 17700001 | The specified bundleName is not found.                        |
1536
| 17700030 | The specified bundle does not support clearing of cache files. |
W
wanghang 已提交
1537 1538 1539 1540

**示例:**

```ts
L
Lotol 已提交
1541
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1542
import hilog from '@ohos.hilog';
W
wanghang 已提交
1543 1544 1545 1546 1547
let bundleName = "com.ohos.myapplication";

try {
    bundleManager.cleanBundleCacheFiles(bundleName, err => {
        if (err) {
G
geng-wenguang 已提交
1548
            hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message);
W
wanghang 已提交
1549
        } else {
G
geng-wenguang 已提交
1550
            hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
W
wanghang 已提交
1551 1552 1553
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1554
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message);
W
wanghang 已提交
1555 1556 1557 1558 1559 1560 1561
}
```

### bundleManager.cleanBundleCacheFiles

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

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

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

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

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

**参数:**

J
junyi233 已提交
1572 1573
| 参数名     | 类型   | 必填 | 说明                                       |
| ---------- | ------ | ---- | ------------------------------------------ |
Z
zhaogan 已提交
1574
| bundleName | string | 是   | 表示要清理其缓存数据的应用程序的bundleName。 |
W
wanghang 已提交
1575 1576 1577 1578 1579

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1586 1587
| 错误码ID | 错误信息                                                   |
| -------- | ---------------------------------------------------------- |
Z
zhaogan 已提交
1588
| 17700001 | The specified bundleName is not found.                      |
J
junyi233 已提交
1589
| 17700030 | The specified bundle does not support clearing of cache files. |
W
wanghang 已提交
1590 1591 1592 1593

**示例:**

```ts
L
Lotol 已提交
1594
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1595
import hilog from '@ohos.hilog';
W
wanghang 已提交
1596 1597 1598
let bundleName = "com.ohos.myapplication";

try {
W
wtt1995 已提交
1599
    bundleManager.cleanBundleCacheFiles(bundleName).then(() => {
G
geng-wenguang 已提交
1600
        hilog.info(0x0000, 'testTag', 'cleanBundleCacheFiles successfully.');
W
wtt1995 已提交
1601
    }).catch(err => {
G
geng-wenguang 已提交
1602
        hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message);
W
wanghang 已提交
1603 1604
    });
} catch (err) {
G
geng-wenguang 已提交
1605
    hilog.error(0x0000, 'testTag', 'cleanBundleCacheFiles failed: %{public}s' + err.message);
W
wanghang 已提交
1606 1607 1608 1609 1610 1611 1612
}
```

### bundleManager.setApplicationEnabled

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

W
wtt1995 已提交
1613
设置指定应用的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
1633
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1634
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1635
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1636 1637 1638 1639

**示例:**

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

try {
    bundleManager.setApplicationEnabled(bundleName, false, err => {
        if (err) {
G
geng-wenguang 已提交
1647
            hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1648
        } else {
G
geng-wenguang 已提交
1649
            hilog.info(0x0000, 'testTag', 'setApplicationEnabled successfully.');
W
wanghang 已提交
1650 1651 1652
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1653
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1654 1655 1656 1657 1658 1659 1660
}
```

### bundleManager.setApplicationEnabled

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

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

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

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

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

**参数:**

J
junyi233 已提交
1671
| 参数名      | 类型    | 必填 | 说明                                  |
W
wanghang 已提交
1672
| ---------- | ------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1673 1674
| bundleName | string  | 是   | 表示应用程序的bundleName。            |
| isEnabled  | boolean | 是   | 值为true表示使能,值为false表示禁用。 |
W
wanghang 已提交
1675 1676 1677 1678 1679

**返回值:**

| 类型           | 说明                                 |
| -------------- | ------------------------------------ |
Z
zhaogan 已提交
1680
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
W
wanghang 已提交
1681 1682 1683

**错误码:**

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

J
junyi233 已提交
1686
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1687
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1688
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1689 1690 1691 1692

**示例:**

```ts
L
Lotol 已提交
1693
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1694
import hilog from '@ohos.hilog';
W
wanghang 已提交
1695 1696 1697
let bundleName = "com.ohos.myapplication";

try {
W
wtt1995 已提交
1698
    bundleManager.setApplicationEnabled(bundleName, false).then(() => {
G
geng-wenguang 已提交
1699
        hilog.info(0x0000, "testTag", "setApplicationEnabled successfully.");
W
wtt1995 已提交
1700
    }).catch(err => {
G
geng-wenguang 已提交
1701
        hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1702 1703
    });
} catch (err) {
G
geng-wenguang 已提交
1704
    hilog.error(0x0000, 'testTag', 'setApplicationEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1705 1706 1707 1708 1709 1710 1711
}
```

### bundleManager.setAbilityEnabled

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

W
wtt1995 已提交
1712
设置指定组件的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1713 1714 1715 1716 1717 1718 1719 1720 1721

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

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

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

**参数:**

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

**错误码:**

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

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

**示例:**

```ts
L
Lotol 已提交
1740
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1741
import hilog from '@ohos.hilog';
W
wanghang 已提交
1742 1743 1744 1745 1746 1747
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
1748
let info;
W
wanghang 已提交
1749 1750 1751

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
G
geng-wenguang 已提交
1752
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo));
W
wanghang 已提交
1753 1754 1755 1756
        info = abilitiesInfo[0];

        bundleManager.setAbilityEnabled(info, false, err => {
            if (err) {
G
geng-wenguang 已提交
1757
                hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1758
            } else {
G
geng-wenguang 已提交
1759
                hilog.info(0x0001, "testTag", "setAbilityEnabled successfully.");
W
wanghang 已提交
1760 1761 1762
            }
        });
    }).catch(error => {
G
geng-wenguang 已提交
1763
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1764 1765
    });
} catch (error) {
G
geng-wenguang 已提交
1766
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1767 1768 1769 1770 1771 1772 1773
}
```

### bundleManager.setAbilityEnabled

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

W
wtt1995 已提交
1774
设置指定组件的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1775 1776 1777 1778 1779 1780 1781 1782 1783

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

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

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

**参数:**

J
junyi233 已提交
1784
| 参数名    | 类型        | 必填 | 说明                                  |
W
wanghang 已提交
1785
| -------- | ----------- | ---- | ------------------------------------- |
Z
zhaogan 已提交
1786 1787
| info     | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 需要被设置的组件。                   |
| isEnabled| boolean     | 是   | 值为true表示使能,值为false表示禁用。 |
W
wanghang 已提交
1788 1789 1790 1791 1792

**返回值:**

| 类型           | 说明                              |
| -------------- | --------------------------------- |
Z
zhaogan 已提交
1793
| Promise\<void> | Promise对象。无返回结果的Promise对象。 |
W
wanghang 已提交
1794 1795 1796

**错误码:**

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

J
junyi233 已提交
1799
| 错误码ID | 错误信息                              |
W
wanghang 已提交
1800
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1801 1802
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityInfo is not found. |
W
wanghang 已提交
1803 1804 1805 1806

**示例:**

```ts
L
Lotol 已提交
1807
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1808
import hilog from '@ohos.hilog';
W
wanghang 已提交
1809 1810 1811 1812 1813 1814
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
1815
let info;
W
wanghang 已提交
1816 1817 1818

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
G
geng-wenguang 已提交
1819
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo));
W
wanghang 已提交
1820 1821
        info = abilitiesInfo[0];

W
wtt1995 已提交
1822
        bundleManager.setAbilityEnabled(info, false).then(() => {
G
geng-wenguang 已提交
1823
            hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
W
wtt1995 已提交
1824
        }).catch(err => {
G
geng-wenguang 已提交
1825
            hilog.error(0x0000, 'testTag', 'setAbilityEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1826 1827
        });
    }).catch(error => {
G
geng-wenguang 已提交
1828
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1829 1830
    });
} catch (error) {
G
geng-wenguang 已提交
1831
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1832 1833 1834 1835 1836 1837 1838
}
```

### bundleManager.isApplicationEnabled

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

W
wtt1995 已提交
1839
以异步的方法获取指定应用的禁用或使能状态,使用callback形式返回结果。
W
wanghang 已提交
1840 1841 1842 1843 1844 1845 1846

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

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

**参数:**

J
junyi233 已提交
1847
| 参数名      | 类型   | 必填 | 说明                       |
W
wanghang 已提交
1848
| ---------- | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
1849 1850
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| callback | AsyncCallback\<boolean> | 是 | 回调函数,返回true表示当前应用为使能状态,返回false表示应用为禁用状态。 |
W
wanghang 已提交
1851 1852 1853

**错误码:**

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

J
junyi233 已提交
1856
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1857
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1858
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1859 1860 1861 1862

**示例:**

```ts
L
Lotol 已提交
1863
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1864
import hilog from '@ohos.hilog';
W
wanghang 已提交
1865 1866 1867 1868 1869
let bundleName = 'com.example.myapplication';

try {
    bundleManager.isApplicationEnabled(bundleName, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
1870
            hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1871
        } else {
G
geng-wenguang 已提交
1872
            hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1873 1874 1875
        }
    });
} catch (err) {
G
geng-wenguang 已提交
1876
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1877 1878 1879 1880 1881 1882 1883
}
```

### bundleManager.isApplicationEnabled

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

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

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

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

**参数:**

J
junyi233 已提交
1892
| 参数名      | 类型   | 必填 | 说明                       |
W
wanghang 已提交
1893
| ---------- | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
1894
| bundleName | string | 是   | 表示应用程序的bundleName。  |
W
wanghang 已提交
1895 1896 1897 1898 1899 1900 1901 1902 1903

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
1906
| 错误码ID | 错误信息                             |
W
wanghang 已提交
1907
| -------- | -------------------------------------- |
Z
zhaogan 已提交
1908
| 17700001 | The specified bundleName is not found. |
W
wanghang 已提交
1909 1910 1911 1912

**示例:**

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

try {
    bundleManager.isApplicationEnabled(bundleName).then((data) => {
G
geng-wenguang 已提交
1919
        hilog.info(0x0000, 'testTag', 'isApplicationEnabled successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1920
    }).catch(error => {
G
geng-wenguang 已提交
1921
        hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1922 1923
    });
} catch (error) {
G
geng-wenguang 已提交
1924
    hilog.error(0x0000, 'testTag', 'isApplicationEnabled failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1925 1926 1927 1928 1929 1930 1931
}
```

### bundleManager.isAbilityEnabled

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

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

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

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

**参数:**

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

**错误码:**

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

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

**示例:**

```ts
L
Lotol 已提交
1957
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
1958
import hilog from '@ohos.hilog';
W
wanghang 已提交
1959 1960 1961 1962 1963 1964
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
1965
let info;
W
wanghang 已提交
1966 1967 1968

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
G
geng-wenguang 已提交
1969
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo));
W
wanghang 已提交
1970 1971 1972 1973
        info = abilitiesInfo[0];

        bundleManager.isAbilityEnabled(info, (err, data) => {
            if (err) {
G
geng-wenguang 已提交
1974
                hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed: %{public}s' + err.message);
W
wanghang 已提交
1975
            } else {
G
geng-wenguang 已提交
1976
                hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
1977 1978 1979
            }
        });
    }).catch(error => {
G
geng-wenguang 已提交
1980
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1981 1982
    });
} catch (error) {
G
geng-wenguang 已提交
1983
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
1984 1985 1986 1987 1988 1989 1990
}
```

### bundleManager.isAbilityEnabled

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

W
wtt1995 已提交
1991
以异步的方法获取指定组件的禁用或使能状态,使用Promise形式返回结果。
W
wanghang 已提交
1992 1993 1994 1995 1996 1997 1998

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

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

**参数:**

J
junyi233 已提交
1999
| 参数名 | 类型        | 必填 | 说明                        |
W
wanghang 已提交
2000
| ---- | ----------- | ---- | --------------------------- |
Z
zhaogan 已提交
2001
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | 是   | 表示关于检查ability的信息。 |
W
wanghang 已提交
2002 2003 2004 2005 2006 2007 2008 2009 2010

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
2013
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2014
| -------- | --------------------------------------- |
Z
zhaogan 已提交
2015 2016
| 17700001 | The specified bundleName is not found.  |
| 17700003 | The specified abilityName is not found. |
W
wanghang 已提交
2017 2018 2019 2020

**示例:**

```ts
L
Lotol 已提交
2021
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2022
import hilog from '@ohos.hilog';
W
wanghang 已提交
2023 2024 2025 2026 2027 2028
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
2029
let info;
W
wanghang 已提交
2030 2031 2032

try {
    bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
G
geng-wenguang 已提交
2033
        hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', + JSON.stringify(abilitiesInfo));
W
wanghang 已提交
2034 2035 2036
        info = abilitiesInfo[0];

        bundleManager.isAbilityEnabled(info).then((data) => {
G
geng-wenguang 已提交
2037
            hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2038
        }).catch(err => {
G
geng-wenguang 已提交
2039
            hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2040 2041
        });
    }).catch(error => {
G
geng-wenguang 已提交
2042
        hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2043 2044
    });
} catch (error) {
G
geng-wenguang 已提交
2045
    hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2046 2047 2048 2049 2050 2051 2052
}
```

### bundleManager.getLaunchWantForBundle

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

W
wtt1995 已提交
2053
以异步方法根据给定的bundleName和userId获取用于启动应用程序的Want参数,使用callback形式返回结果。
W
wanghang 已提交
2054 2055 2056 2057 2058 2059 2060 2061 2062

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

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

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

**参数:**

J
junyi233 已提交
2063
| 参数名     | 类型                 | 必填 | 说明                                                         |
W
wanghang 已提交
2064
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2065 2066 2067
| bundleName | string               | 是   | 表示应用程序的bundleName。                                     |
| userId     | number               | 是   | 表示用户ID。                                                   |
| callback   | AsyncCallback\<Want> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Want;否则为错误对象。 |
W
wanghang 已提交
2068 2069 2070

**错误码:**

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

J
junyi233 已提交
2073
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2074
| -------- | --------------------------------------|
Z
zhaogan 已提交
2075
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2076
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2077
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2078 2079 2080 2081

**示例:**

```ts
L
Lotol 已提交
2082
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2083
import hilog from '@ohos.hilog';
W
wanghang 已提交
2084 2085 2086 2087 2088 2089
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
2090
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message);
W
wanghang 已提交
2091
        } else {
G
geng-wenguang 已提交
2092
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2093 2094 2095
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2096
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message);
W
wanghang 已提交
2097 2098 2099 2100 2101 2102 2103
}
```

### bundleManager.getLaunchWantForBundle

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

W
wtt1995 已提交
2104
以异步方法根据给定的bundleName获取用于启动应用程序的Want参数,使用callback形式返回结果。
W
wanghang 已提交
2105 2106 2107 2108 2109 2110 2111 2112 2113

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

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

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

**参数:**

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

**错误码:**

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

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

**示例:**

```ts
L
Lotol 已提交
2132
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2133
import hilog from '@ohos.hilog';
W
wanghang 已提交
2134 2135 2136 2137 2138
let bundleName = 'com.example.myapplication';

try {
    bundleManager.getLaunchWantForBundle(bundleName, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
2139
            hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message);
W
wanghang 已提交
2140
        } else {
G
geng-wenguang 已提交
2141
            hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2142 2143 2144
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2145
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed: %{public}s' + err.message);
W
wanghang 已提交
2146 2147 2148 2149 2150 2151 2152
}
```

### bundleManager.getLaunchWantForBundle

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

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

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

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

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

**参数:**

Z
zhaogan 已提交
2163 2164 2165 2166
| 参数名     | 类型   | 必填 | 说明                       |
| ---------- | ------ | ---- | ------------------------- |
| bundleName | string | 是   | 表示应用程序的bundleName。 |
| userId     | number | 否   | 表示用户ID。               |
W
wanghang 已提交
2167 2168 2169 2170 2171

**返回值:**

| 类型           | 说明                      |
| -------------- | ------------------------- |
Z
zhaogan 已提交
2172
| Promise\<Want> | Promise对象,返回Want对象。 |
W
wanghang 已提交
2173 2174 2175

**错误码:**

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

J
junyi233 已提交
2178
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2179
| -------- | --------------------------------------|
Z
zhaogan 已提交
2180
| 17700001 | The specified bundleName is not found. |
2181
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2182
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2183 2184 2185 2186

**示例:**

```ts
L
Lotol 已提交
2187
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2188
import hilog from '@ohos.hilog';
W
wanghang 已提交
2189 2190 2191 2192 2193
let bundleName = 'com.example.myapplication';
let userId = 100;

try {
    bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => {
G
geng-wenguang 已提交
2194
        hilog.info(0x0000, 'testTag', 'getLaunchWantForBundle successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2195
    }).catch(error => {
G
geng-wenguang 已提交
2196
        hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2197 2198
    });
} catch (error) {
G
geng-wenguang 已提交
2199
    hilog.error(0x0000, 'testTag', 'getLaunchWantForBundle failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212
}
```

### 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 已提交
2213
| 参数名       | 类型                          | 必填 | 说明                                                         |
W
wanghang 已提交
2214
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2215 2216 2217 2218
| moduleName   | string                        | 是   | 表示应用程序的moduleName。                                     |
| abilityName  | string                        | 是   | 表示应用程序的abilityName。                                    |
| metadataName | string                        | 是   | 表示应用程序的metadataName。                                  |
| callback     | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
W
wanghang 已提交
2219 2220 2221

**错误码:**

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

J
junyi233 已提交
2224
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2225
| -------- | ------------------------------------------------------------ |
Z
zhongjianfei 已提交
2226 2227
| 17700002 | The specified moduleName does not exist.                      |
| 17700003 | The specified abilityName does not exist.                     |
2228
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2229 2230
| 17700026 | The specified bundle is disabled.                             |
| 17700029 | The specified ability is disabled.                            |
W
wanghang 已提交
2231 2232 2233 2234

**示例:**

```ts
L
Lotol 已提交
2235
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2236
import hilog from '@ohos.hilog';
W
wanghang 已提交
2237 2238 2239 2240 2241 2242 2243
let moduleName = 'entry';
let abilityName = 'MainAbility';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
2244
            hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2245
        } else {
G
geng-wenguang 已提交
2246
            hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2247 2248 2249
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2250
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263
}
```

### bundleManager.getProfileByAbility

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

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

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

**参数:**

J
junyi233 已提交
2264
| 参数名       | 类型   | 必填 | 说明                       |
W
wanghang 已提交
2265
| ------------ | ------ | ---- | -------------------------- |
Z
zhaogan 已提交
2266 2267 2268
| moduleName   | string | 是   | 表示应用程序的moduleName。   |
| abilityName  | string | 是   | 表示应用程序的abilityName。  |
| metadataName | string | 否   | 表示应用程序的metadataName。 |
W
wanghang 已提交
2269 2270 2271 2272 2273

**返回值:**

| 类型                    | 说明                            |
| ----------------------- | ------------------------------- |
Z
zhaogan 已提交
2274
| Promise<Array\<string>> | Promise对象,返回Array\<string>。 |
W
wanghang 已提交
2275 2276 2277

**错误码:**

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

J
junyi233 已提交
2280
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2281
| -------- | ------------------------------------------------------------ |
Z
zhongjianfei 已提交
2282 2283
| 17700002 | The specified moduleName does not exist.                      |
| 17700003 | The specified abilityName does not exist.                     |
2284
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2285 2286
| 17700026 | The specified bundle is disabled.                             |
| 17700029 | The specified ability is disabled.                            |
W
wanghang 已提交
2287 2288 2289 2290

**示例:**

```ts
L
Lotol 已提交
2291
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2292
import hilog from '@ohos.hilog';
W
wanghang 已提交
2293 2294 2295 2296 2297
let moduleName = 'entry';
let abilityName = 'MainAbility';

try {
    bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
G
geng-wenguang 已提交
2298
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2299
    }).catch(error => {
G
geng-wenguang 已提交
2300
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2301 2302
    });
} catch (error) {
G
geng-wenguang 已提交
2303
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2304
}
Z
zhaogan 已提交
2305
```
W
wanghang 已提交
2306

Z
zhaogan 已提交
2307
```ts
L
Lotol 已提交
2308
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2309
import hilog from '@ohos.hilog';
Z
zhaogan 已提交
2310 2311 2312
let moduleName = 'entry';
let abilityName = 'MainAbility';
let metadataName = 'com.example.myapplication.metadata';
W
wanghang 已提交
2313
try {
Z
zhaogan 已提交
2314
    bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
G
geng-wenguang 已提交
2315
        hilog.info(0x0000, 'testTag', 'getProfileByAbility successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2316
    }).catch(error => {
G
geng-wenguang 已提交
2317
        hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2318 2319
    });
} catch (error) {
G
geng-wenguang 已提交
2320
    hilog.error(0x0000, 'testTag', 'getProfileByAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333
}
```

### bundleManager.getProfileByExtensionAbility

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

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

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

**参数:**

2334
| 参数名                 | 类型                          | 必填 | 说明                                                         |
W
wanghang 已提交
2335
| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ |
J
junyi233 已提交
2336 2337 2338
| moduleName           | string                        | 是   | 表示应用程序的moduleName。                                   |
| extensionAbilityName | string                        | 是   | 表示应用程序的extensionAbilityName。                         |
| metadataName         | string                        | 是   | 表示应用程序的metadataName。                                 |
Z
zhaogan 已提交
2339
| callback             | AsyncCallback<Array\<string>> | 是   | 回调函数,当获取成功时,err为null,data为获取到的Array\<string>;否则为错误对象。 |
W
wanghang 已提交
2340 2341 2342

**错误码:**

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

J
junyi233 已提交
2345
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2346
| -------- | ------------------------------------------------------------ |
Z
zhongjianfei 已提交
2347
| 17700002 | The specified moduleName does not exist.                      |
J
junyi233 已提交
2348
| 17700003 | The specified extensionAbilityName not existed.            |
2349
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2350
| 17700026 | The specified bundle is disabled.                             |
W
wanghang 已提交
2351 2352 2353 2354

**示例:**

```ts
L
Lotol 已提交
2355
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2356
import hilog from '@ohos.hilog';
W
wanghang 已提交
2357 2358 2359 2360 2361 2362 2363
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) {
G
geng-wenguang 已提交
2364
            hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s' + err.message);
W
wanghang 已提交
2365
        } else {
G
geng-wenguang 已提交
2366
            hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2367 2368 2369
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2370
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed: %{public}s' + err.message);
W
wanghang 已提交
2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383
}
```

### bundleManager.getProfileByExtensionAbility

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

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

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

**参数:**

2384
| 参数名                 | 类型   | 必填 | 说明                               |
J
junyi233 已提交
2385
| -------------------- | ------ | ---- | ---------------------------------- |
Z
zhaogan 已提交
2386 2387 2388
| moduleName           | string | 是   | 表示应用程序的moduleName。           |
| extensionAbilityName | string | 是   | 表示应用程序的extensionAbilityName。 |
| metadataName         | string | 否   | 表示应用程序的metadataName。         |
W
wanghang 已提交
2389 2390 2391 2392 2393

**返回值:**

| 类型                    | 说明                                |
| ----------------------- | ----------------------------------- |
Z
zhaogan 已提交
2394
| Promise<Array\<string>> | Promise对象,返回Array\<string>对象。 |
W
wanghang 已提交
2395 2396 2397

**错误码:**

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

J
junyi233 已提交
2400
| 错误码ID | 错误信息                                                     |
W
wanghang 已提交
2401
| -------- | ------------------------------------------------------------ |
Z
zhongjianfei 已提交
2402
| 17700002 | The specified moduleName does not exist.                      |
J
junyi233 已提交
2403
| 17700003 | The specified extensionAbilityName not existed.            |
2404
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
Z
zhaogan 已提交
2405
| 17700026 | The specified bundle is disabled.                             |
W
wanghang 已提交
2406 2407 2408 2409

**示例:**

```ts
L
Lotol 已提交
2410
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2411
import hilog from '@ohos.hilog';
W
wanghang 已提交
2412 2413 2414 2415 2416 2417
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';

try {
    bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
G
geng-wenguang 已提交
2418
        hilog.info(0x0000, 'testTag', 'getProfileByExtensionAbility successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2419
    }).catch(error => {
G
geng-wenguang 已提交
2420
        hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2421 2422
    });
} catch (error) {
G
geng-wenguang 已提交
2423
    hilog.error(0x0000, 'testTag', 'getProfileByExtensionAbility failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2424 2425 2426 2427
}

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

### bundleManager.getPermissionDef

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

W
wtt1995 已提交
2441
以异步方法根据给定的permissionName获取权限定义结构体PermissionDef信息,使用callback形式返回结果。
W
wanghang 已提交
2442 2443 2444 2445 2446 2447 2448 2449 2450

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

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

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

**参数:**

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

**错误码:**

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

J
junyi233 已提交
2460 2461
| 错误码ID | 错误信息                              |
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2462
| 17700006 | The specified permission is not found. |
W
wanghang 已提交
2463 2464 2465 2466

**示例:**

```ts
L
Lotol 已提交
2467
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2468
import hilog from '@ohos.hilog';
W
wanghang 已提交
2469 2470 2471 2472
let permission = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permission, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
2473
            hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s' + err.message);
W
wanghang 已提交
2474
        } else {
G
geng-wenguang 已提交
2475
            hilog.info(0x0000, 'testTag', 'getPermissionDef successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2476 2477 2478
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2479
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed: %{public}s' + err.message);
W
wanghang 已提交
2480 2481 2482 2483 2484 2485 2486
}
```

### bundleManager.getPermissionDef

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

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

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

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

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

**参数:**

2497
| 参数名           | 类型   | 必填 | 说明           |
J
junyi233 已提交
2498
| -------------- | ------ | ---- | -------------- |
Z
zhaogan 已提交
2499
| permissionName | string | 是   | 表示权限参数名。 |
W
wanghang 已提交
2500 2501 2502 2503 2504

**返回值:**

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

**错误码:**

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

J
junyi233 已提交
2511 2512
| 错误码ID | 错误信息                              |
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2513
| 17700006 | The specified permission is not found. |
W
wanghang 已提交
2514 2515 2516 2517

**示例:**

```ts
L
Lotol 已提交
2518
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2519
import hilog from '@ohos.hilog';
W
wanghang 已提交
2520 2521 2522
let permissionName = "ohos.permission.GET_BUNDLE_INFO";
try {
    bundleManager.getPermissionDef(permissionName).then((data) => {
G
geng-wenguang 已提交
2523
        hilog.info(0x0000, 'testTag', 'getPermissionDef successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2524
    }).catch(error => {
G
geng-wenguang 已提交
2525
        hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2526 2527
    });
} catch (error) {
G
geng-wenguang 已提交
2528
    hilog.error(0x0000, 'testTag', 'getPermissionDef failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545
}
```

### 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 已提交
2546
| 参数名      | 类型                   | 必填 | 说明                                                         |
W
wanghang 已提交
2547
| ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2548 2549 2550 2551
| bundleName  | string                 | 是   | 表示应用程序的bundleName。                                     |
| moduleName  | string                 | 是   | 表示应用程序的moduleName。                                     |
| abilityName | string                 | 是   | 表示应用程序的abilityName。                                    |
| callback    | AsyncCallback\<string> | 是   | 回调函数,当获取成功时,err为null,data为获指定组件的Label值;否则为错误对象。 |
W
wanghang 已提交
2552 2553 2554

**错误码:**

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

J
junyi233 已提交
2557 2558
| 错误码ID | 错误信息                               |
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2559 2560 2561 2562 2563
| 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 已提交
2564 2565 2566 2567

**示例:**

```ts
L
Lotol 已提交
2568
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2569
import hilog from '@ohos.hilog';
W
wanghang 已提交
2570 2571 2572 2573 2574 2575 2576
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
2577
            hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s' + err.message);
W
wanghang 已提交
2578
        } else {
G
geng-wenguang 已提交
2579
            hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2580 2581 2582
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2583
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed: %{public}s' + err.message);
W
wanghang 已提交
2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600
}
```

### 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 已提交
2601
| 参数名      | 类型   | 必填 | 说明                      |
W
wanghang 已提交
2602
| ----------- | ------ | ---- | ------------------------- |
Z
zhaogan 已提交
2603 2604 2605
| bundleName  | string | 是   | 表示应用程序的bundleName。  |
| moduleName  | string | 是   | 表示应用程序的moduleName。  |
| abilityName | string | 是   | 表示应用程序的abilityName。 |
W
wanghang 已提交
2606 2607 2608 2609 2610

**返回值:**

| 类型             | 说明                                |
| ---------------- | ----------------------------------- |
Z
zhaogan 已提交
2611
| Promise\<string> | Promise对象,返回指定组件的Lablel值。 |
W
wanghang 已提交
2612 2613 2614

**错误码:**

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

J
junyi233 已提交
2617
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2618
| -------- | --------------------------------------- |
Z
zhaogan 已提交
2619 2620 2621 2622 2623
| 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 已提交
2624 2625 2626 2627

**示例:**

```ts
L
Lotol 已提交
2628
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2629
import hilog from '@ohos.hilog';
W
wanghang 已提交
2630 2631 2632 2633 2634 2635
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';

try {
    bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => {
G
geng-wenguang 已提交
2636
        hilog.info(0x0000, 'testTag', 'getAbilityLabel successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2637
    }).catch(error => {
G
geng-wenguang 已提交
2638
        hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2639 2640
    });
} catch (error) {
G
geng-wenguang 已提交
2641
    hilog.error(0x0000, 'testTag', 'getAbilityLabel failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658
}
```

### bundleManager.getAbilityIcon

getAbilityIcon(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)>): void;

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

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

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

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

**参数:**

J
junyi233 已提交
2659
| 参数名      | 类型                                                        | 必填 | 说明                                                         |
W
wanghang 已提交
2660
| ----------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
Z
zhaogan 已提交
2661 2662 2663 2664
| bundleName  | string                                                      | 是   | 表示应用程序的bundleName。                                     |
| moduleName  | string                                                      | 是   | 表示应用程序的moduleName。                                     |
| abilityName | string                                                      | 是   | 表示应用程序的abilityName。                                    |
| callback    | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | 是   | 回调函数,当获取成功时,err为null,data为指定组件icon的PixelMap对象;否则为错误对象。 |
W
wanghang 已提交
2665 2666 2667

**错误码:**

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

J
junyi233 已提交
2670
| 错误码ID | 错误信息                              |
W
wanghang 已提交
2671
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2672 2673 2674 2675 2676
| 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 已提交
2677 2678 2679 2680

**示例:**

```ts
L
Lotol 已提交
2681
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2682
import hilog from '@ohos.hilog';
W
wanghang 已提交
2683 2684 2685 2686 2687 2688 2689
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';

try {
    bundleManager.getAbilityIcon(bundleName, moduleName, abilityName, (err, data) => {
        if (err) {
G
geng-wenguang 已提交
2690
            hilog.error(0x0000, 'testTag', 'getAbilityIcon failed: %{public}s' + err.message);
W
wanghang 已提交
2691
        } else {
G
geng-wenguang 已提交
2692
            hilog.info(0x0000, 'testTag', 'getAbilityIcon successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2693 2694 2695
        }
    });
} catch (err) {
G
geng-wenguang 已提交
2696
    hilog.error(0x0000, 'testTag', 'getAbilityIcon failed: %{public}s' + err.message);
W
wanghang 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713
}
```

### bundleManager.getAbilityIcon

getAbilityIcon(bundleName: string, moduleName: string, abilityName: string): Promise<[image.PixelMap](js-apis-image.md#pixelmap7)>;

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

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

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

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

**参数:**

J
junyi233 已提交
2714
| 参数名      | 类型   | 必填 | 说明                      |
W
wanghang 已提交
2715
| ----------- | ------ | ---- | ------------------------- |
Z
zhaogan 已提交
2716 2717 2718
| bundleName  | string | 是   | 表示应用程序的bundleName。  |
| moduleName  | string | 是   | 表示应用程序的moduleName。  |
| abilityName | string | 是   | 表示应用程序的abilityName。 |
W
wanghang 已提交
2719 2720 2721 2722 2723

**返回值:**

| 类型                                                  | 说明                                        |
| ----------------------------------------------------- | ------------------------------------------- |
Z
zhaogan 已提交
2724
| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise对象,返回指定组件icon的PixelMap对象。 |
W
wanghang 已提交
2725 2726 2727

**错误码:**

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

J
junyi233 已提交
2730
| 错误码ID | 错误信息                               |
W
wanghang 已提交
2731
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2732 2733 2734 2735 2736
| 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 已提交
2737 2738 2739 2740

**示例:**

```ts
L
Lotol 已提交
2741
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2742
import hilog from '@ohos.hilog';
W
wanghang 已提交
2743 2744 2745 2746 2747 2748
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';

try {
    bundleManager.getAbilityIcon(bundleName, moduleName, abilityName).then((data) => {
G
geng-wenguang 已提交
2749
        hilog.info(0x0000, 'testTag', 'getAbilityIcon successfully. Data: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2750
    }).catch(error => {
G
geng-wenguang 已提交
2751
        hilog.error(0x0000, 'testTag', 'getAbilityIcon failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2752 2753
    });
} catch (error) {
G
geng-wenguang 已提交
2754
    hilog.error(0x0000, 'testTag', 'getAbilityIcon failed. Cause: %{public}s' + err.message);
W
wanghang 已提交
2755 2756 2757 2758 2759 2760 2761
}
```

### bundleManager.getApplicationInfoSync

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

W
wtt1995 已提交
2762
以同步方法根据给定的bundleName、applicationFlags和userId获取ApplicationInfo。
W
wanghang 已提交
2763 2764 2765 2766 2767

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

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

W
wtt1995 已提交
2768
**系统能力:** SystemCapability.BundleManager.BundleFramework.Core。
W
wanghang 已提交
2769 2770 2771

**参数:**

J
junyi233 已提交
2772
| 参数名       | 类型   | 必填 | 说明                                                       |
W
wanghang 已提交
2773
| ----------- | ------ | ---- | ----------------------------------------------------------|
Z
zhaogan 已提交
2774 2775
| bundleName  | string | 是   | 表示应用程序的bundleName。                                  |
| applicationFlags | [number](#applicationflag) | 是   | 表示用于指定将返回的ApplicationInfo对象中包含的信息。       |
Z
zhoagan 已提交
2776
| userId      | number | 否   | 表示用户ID。                                         |
W
wanghang 已提交
2777 2778 2779 2780 2781

**返回值:**

| 类型            | 说明                      |
| --------------- | ------------------------- |
Z
zhaogan 已提交
2782
| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | 返回ApplicationInfo对象。 |
W
wanghang 已提交
2783 2784 2785

**错误码:**

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

J
junyi233 已提交
2788
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2789
| -------- | -------------------------------------- |
Z
zhaogan 已提交
2790
| 17700001 | The specified bundleName is not found. |
J
junyi233 已提交
2791
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2792
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2793 2794 2795 2796

**示例:**

```ts
L
Lotol 已提交
2797
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2798
import hilog from '@ohos.hilog';
W
wanghang 已提交
2799 2800 2801 2802 2803 2804
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId);
G
geng-wenguang 已提交
2805
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2806
} catch (err) {
G
geng-wenguang 已提交
2807
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s' + err.message);
W
wanghang 已提交
2808 2809 2810 2811
}
```

```ts
L
Lotol 已提交
2812
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2813
import hilog from '@ohos.hilog';
W
wanghang 已提交
2814 2815 2816 2817 2818
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;

try {
    let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags);
G
geng-wenguang 已提交
2819
    hilog.info(0x0000, 'testTag', 'getApplicationInfoSync successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2820
} catch (err) {
G
geng-wenguang 已提交
2821
    hilog.error(0x0000, 'testTag', 'getApplicationInfoSync failed: %{public}s' + err.message);
W
wanghang 已提交
2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838
}
```

### bundleManager.getBundleInfoSync

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

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

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

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

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

**参数:**

J
junyi233 已提交
2839
| 参数名       | 类型   | 必填 | 说明                                                     |
W
wanghang 已提交
2840
| ----------- | ------ | ---- | -------------------------------------------------------- |
Z
zhaogan 已提交
2841 2842
| bundleName  | string | 是   | 表示应用程序的bundleName。                                 |
| bundleFlags | [number](#bundleflag) | 是   | 表示用于指定将返回的BundleInfo对象中包含的信息的标志。 |
Z
zhoagan 已提交
2843
| userId      | number | 否   | 表示用户ID。                                             |
W
wanghang 已提交
2844 2845 2846 2847 2848

**返回值:**

| 类型       | 说明                 |
| ---------- | -------------------- |
Z
zhaogan 已提交
2849
| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | 返回BundleInfo对象。 |
W
wanghang 已提交
2850 2851 2852

**错误码:**

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

J
junyi233 已提交
2855
| 错误码ID | 错误信息                             |
W
wanghang 已提交
2856
| -------- | ------------------------------------- |
Z
zhaogan 已提交
2857
| 17700001 | The specified bundleName is not found. |
2858
| 17700004 | The specified user ID is not found.     |
Z
zhaogan 已提交
2859
| 17700026 | The specified bundle is disabled.      |
W
wanghang 已提交
2860 2861 2862 2863

**示例:**

```ts
L
Lotol 已提交
2864
import bundleManager from '@ohos.bundle.bundleManager';
G
geng-wenguang 已提交
2865
import hilog from '@ohos.hilog';
W
wanghang 已提交
2866 2867 2868 2869 2870 2871
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);
G
geng-wenguang 已提交
2872
    hilog.info(0x0000, 'testTag', 'getBundleInfoSync successfully: %{public}s', + JSON.stringify(data));
W
wanghang 已提交
2873
} catch (err) {
G
geng-wenguang 已提交
2874
    hilog.error(0x0000, 'testTag', 'getBundleInfoSync failed: %{public}s' + err.message);
W
wanghang 已提交
2875 2876 2877 2878
}
```

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