js-apis-Bundle.md 56.2 KB
Newer Older
W
wusongqing 已提交
1 2
# Bundle Module (JavaScript SDK APIs)

W
wusongqing 已提交
3
> **NOTE**<br>
W
wusongqing 已提交
4
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
5
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
W
wusongqing 已提交
6 7 8 9 10 11
## Modules to Import

```
import bundle from '@ohos.bundle';
```

W
wusongqing 已提交
12
## System Capability
W
wusongqing 已提交
13 14 15 16 17

SystemCapability.BundleManager.BundleFramework

## Required Permissions

Z
zengyawen 已提交
18 19 20
| Required Permissions                                      | Permission Level        | Description       |
| ---------------------------------------- | ------------ | --------- |
| ohos.permission.GET_BUNDLE_INFO          | normal       | Permission to query information about the current application.|
W
wusongqing 已提交
21
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to query information about all applications.|
Z
zengyawen 已提交
22
| ohos.permission.INSTALL_BUNDLE           | system_core  | Permission to install or uninstall applications. |
W
wusongqing 已提交
23 24 25

## bundle.getApplicationInfo

W
wusongqing 已提交
26
getApplicationInfo(bundleName: string, bundleFlags: number, userId?: number): Promise\<ApplicationInfo>
W
wusongqing 已提交
27

Z
zengyawen 已提交
28
Obtains the application information based on a given bundle name. This API uses a promise to return the result.
W
wusongqing 已提交
29

W
wusongqing 已提交
30
**Required permissions**
W
wusongqing 已提交
31

W
wusongqing 已提交
32 33 34 35 36
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
37 38 39

**Parameters**

Z
zengyawen 已提交
40 41 42 43 44
| Name         | Type    | Mandatory  | Description                                     |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleName  | string | Yes   | Bundle name of the application.                           |
| bundleFlags | number | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId      | number | No   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.           |
W
wusongqing 已提交
45 46 47

**Return value**

Z
zengyawen 已提交
48 49
| Type                       | Description                |
| ------------------------- | ------------------ |
W
wusongqing 已提交
50
| Promise\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Promise used to return the application information.|
W
wusongqing 已提交
51 52 53 54

**Example**

```js
W
wusongqing 已提交
55 56 57 58 59 60 61 62
let bundleName = "com.example.myapplication";
let bundleFlags = 0;
let userId = 100;
bundle.getApplicationInfo(bundleName, bundleFlags, userId)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
W
wusongqing 已提交
63 64 65 66 67 68 69 70 71
})
```



## bundle.getApplicationInfo

getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<ApplicationInfo>): void

Z
zengyawen 已提交
72
Obtains the application information based on a given bundle name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
73

W
wusongqing 已提交
74
**Required permissions**
W
wusongqing 已提交
75

W
wusongqing 已提交
76 77 78 79 80
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
81 82 83

**Parameters**

Z
zengyawen 已提交
84 85 86 87 88
| Name         | Type                             | Mandatory  | Description                                     |
| ----------- | ------------------------------- | ---- | --------------------------------------- |
| bundleName  | string                          | Yes   | Bundle name of the application.                           |
| bundleFlags | number                          | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId      | number                          | Yes   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.           |
W
wusongqing 已提交
89
| callback    | AsyncCallback\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Yes   | Callback used to return the application information.                |
W
wusongqing 已提交
90 91 92 93

**Example**

```js
W
wusongqing 已提交
94 95 96 97 98 99 100 101 102 103
let bundleName = "com.example.myapplication";
let bundleFlags = 0;
let userId = 100;
bundle.getApplicationInfo(bundleName, bundleFlags, userId, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
 })
W
wusongqing 已提交
104 105 106
```


W
wusongqing 已提交
107 108 109 110
## bundle.getApplicationInfo

getApplicationInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<ApplicationInfo>): void

Z
zengyawen 已提交
111
Obtains the application information based on a given bundle name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
112 113 114 115 116 117 118 119 120 121 122

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
123 124 125 126
| Name         | Type                             | Mandatory  | Description                                     |
| ----------- | ------------------------------- | ---- | --------------------------------------- |
| bundleName  | string                          | Yes   | Bundle name of the application.                           |
| bundleFlags | number                          | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
W
wusongqing 已提交
127
| callback    | AsyncCallback\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)> | Yes   | Callback used to return the application information.                |
W
wusongqing 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

**Example**

```js
let bundleName = "com.example.myapplication";
let bundleFlags = 0;
bundle.getApplicationInfo(bundleName, bundleFlags, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
 })
```

W
wusongqing 已提交
143 144 145

## bundle.getAllBundleInfo

W
wusongqing 已提交
146
getAllBundleInfo(bundleFlag: BundleFlag, userId?: number): Promise<Array\<BundleInfo>>
W
wusongqing 已提交
147

Z
zengyawen 已提交
148
Obtains the information of all available bundles of a specified user in the system. This API uses a promise to return the result.
W
wusongqing 已提交
149

W
wusongqing 已提交
150
**Required permissions**
W
wusongqing 已提交
151

W
wusongqing 已提交
152 153 154 155 156
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
157 158 159

**Parameters**

Z
zengyawen 已提交
160 161 162 163
| Name        | Type        | Mandatory  | Description                                     |
| ---------- | ---------- | ---- | --------------------------------------- |
| bundleFlag | BundleFlag | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId     | number     | No   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.           |
W
wusongqing 已提交
164 165 166

**Return value**

Z
zengyawen 已提交
167 168
| Type                         | Description                        |
| --------------------------- | -------------------------- |
W
wusongqing 已提交
169
| Promise<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Promise used to return the information of all available bundles.|
W
wusongqing 已提交
170 171 172 173

**Example**

```js
W
wusongqing 已提交
174 175 176 177 178 179 180
let bundleFlag = 0;
let userId = 100;
bundle.getAllBundleInfo(bundleFlag, userId)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
W
wusongqing 已提交
181 182 183 184 185 186 187 188 189
})
```



## bundle.getAllBundleInfo

getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback<Array\<BundleInfo>>): void

Z
zengyawen 已提交
190
Obtains the information of all available bundles in the system. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
191

W
wusongqing 已提交
192
**Required permissions**
W
wusongqing 已提交
193

W
wusongqing 已提交
194 195 196 197 198
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
199 200 201

**Parameters**

Z
zengyawen 已提交
202 203 204
| Name        | Type                               | Mandatory  | Description                                     |
| ---------- | --------------------------------- | ---- | --------------------------------------- |
| bundleFlag | BundleFlag                        | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
W
wusongqing 已提交
205
| callback   | AsyncCallback<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Yes   | Callback used to return the information of all available bundles.       |
W
wusongqing 已提交
206 207 208 209

**Example**

```js
W
wusongqing 已提交
210 211 212 213 214 215 216 217 218
let bundleFlag = 0;
bundle.getAllBundleInfo(bundleFlag, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
 })
```
W
wusongqing 已提交
219

W
wusongqing 已提交
220 221 222 223 224

## bundle.getAllBundleInfo

getAllBundleInfo(bundleFlag: BundleFlag, userId: number, callback: AsyncCallback<Array\<BundleInfo>>): void

Z
zengyawen 已提交
225
Obtains the information of all available bundles in the system. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
226 227 228

**Required permissions**

W
wusongqing 已提交
229 230 231 232 233
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
234 235 236

**Parameters**

Z
zengyawen 已提交
237 238 239 240
| Name        | Type                               | Mandatory  | Description                                     |
| ---------- | --------------------------------- | ---- | --------------------------------------- |
| bundleFlag | BundleFlag                        | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId     | number                            | Yes   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.           |
W
wusongqing 已提交
241
| callback   | AsyncCallback<Array\<[BundleInfo](js-apis-bundle-BundleInfo.md)>> | Yes   | Callback used to return the information of all available bundles.       |
W
wusongqing 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254

**Example**

```js
let bundleFlag = 0;
let userId = 100;
bundle.getAllBundleInfo(bundleFlag, userId, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
 })
W
wusongqing 已提交
255 256 257 258 259 260
```



## bundle.getBundleInfo

W
wusongqing 已提交
261
getBundleInfo(bundleName: string, bundleFlags: number, options?: BundleOptions): Promise\<BundleInfo>
W
wusongqing 已提交
262

Z
zengyawen 已提交
263
Obtains the bundle information based on a given bundle name. This API uses a promise to return the result.
W
wusongqing 已提交
264

W
wusongqing 已提交
265
**Required permissions**
W
wusongqing 已提交
266

W
wusongqing 已提交
267 268 269 270 271
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
272 273 274

**Parameters**

Z
zengyawen 已提交
275 276
| Name         | Type           | Mandatory  | Description                                     |
| ----------- | ------------- | ---- | --------------------------------------- |
W
wusongqing 已提交
277
| bundleName  | string        | Yes   | Bundle name of the application.                                     |
Z
zengyawen 已提交
278
| bundleFlags | number        | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
W
wusongqing 已提交
279
| options     | [BundleOptions](#bundleoptions)| No   | Includes **userId**.                              |
W
wusongqing 已提交
280 281 282

**Return value**

Z
zengyawen 已提交
283 284
| Type                  | Description                          |
| -------------------- | ---------------------------- |
W
wusongqing 已提交
285
| Promise\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Promise used to return the bundle information.|
W
wusongqing 已提交
286 287 288 289

**Example**

```js
W
wusongqing 已提交
290 291 292
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
let options = {
W
wusongqing 已提交
293
  "userId" : 100
W
wusongqing 已提交
294 295 296 297 298 299
};
bundle.getBundleInfo(bundleName, bundleFlags, options)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
W
wusongqing 已提交
300 301 302 303 304 305 306 307 308
})
```



## bundle.getBundleInfo

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

Z
zengyawen 已提交
309
Obtains the bundle information based on a given bundle name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
310

W
wusongqing 已提交
311
**Required permissions**
W
wusongqing 已提交
312

W
wusongqing 已提交
313 314 315 316 317
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
318 319 320

**Parameters**

Z
zengyawen 已提交
321 322
| Name         | Type                        | Mandatory  | Description                                     |
| ----------- | -------------------------- | ---- | --------------------------------------- |
W
wusongqing 已提交
323
| bundleName  | string                     | Yes   | Bundle name of the application.                                     |
Z
zengyawen 已提交
324
| bundleFlags | number                     | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
W
wusongqing 已提交
325
| callback    | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes   | Callback used to return the bundle information.                   |
W
wusongqing 已提交
326 327 328 329

**Example**

```js
W
wusongqing 已提交
330 331 332 333 334 335 336 337 338
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
bundle.getBundleInfo(bundleName, bundleFlags, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
W
wusongqing 已提交
339 340 341
```


W
wusongqing 已提交
342 343 344 345
## bundle.getBundleInfo

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

Z
zengyawen 已提交
346
Obtains the bundle information based on a given bundle name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
347 348 349

**Required permissions**

W
wusongqing 已提交
350 351 352 353 354
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
355 356 357

**Parameters**

Z
zengyawen 已提交
358 359
| Name         | Type                        | Mandatory  | Description                                     |
| ----------- | -------------------------- | ---- | --------------------------------------- |
W
wusongqing 已提交
360
| bundleName  | string                     | Yes   | Bundle name of the application.                                     |
Z
zengyawen 已提交
361
| bundleFlags | number                     | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
W
wusongqing 已提交
362 363
| options     | [BundleOptions](#bundleoptions)             | Yes   | Includes **userId**.                              |
| callback    | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes   | Callback used to return the bundle information.                   |
W
wusongqing 已提交
364 365 366 367 368 369 370

**Example**

```js
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
let options = {
W
wusongqing 已提交
371
  "userId" : 100
W
wusongqing 已提交
372 373 374 375 376 377 378 379 380 381
};
bundle.getBundleInfo(bundleName, bundleFlags, options, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
382 383 384

## bundle.getAllApplicationInfo

W
wusongqing 已提交
385
getAllApplicationInfo(bundleFlags: number, userId?: number): Promise<Array\<ApplicationInfo>>
W
wusongqing 已提交
386

Z
zengyawen 已提交
387
Obtains the information about all applications of the specified user. This API uses a promise to return the result.
W
wusongqing 已提交
388

W
wusongqing 已提交
389
**Required permissions**
W
wusongqing 已提交
390

W
wusongqing 已提交
391 392 393 394 395
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
396 397 398

**Parameters**

Z
zengyawen 已提交
399 400 401 402
| Name         | Type    | Mandatory  | Description                                     |
| ----------- | ------ | ---- | --------------------------------------- |
| bundleFlags | number | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId      | number | No   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.           |
W
wusongqing 已提交
403 404 405

**Return value**

Z
zengyawen 已提交
406 407
| Type                              | Description                             |
| -------------------------------- | ------------------------------- |
W
wusongqing 已提交
408
| Promise<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Promise used to return the application information.|
W
wusongqing 已提交
409 410 411 412

**Example**

```js
W
wusongqing 已提交
413 414 415 416 417 418 419
let bundleFlags = 8;
let userId = 100;
bundle.getAllApplicationInfo(bundleFlags, userId)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
W
wusongqing 已提交
420 421 422 423 424 425 426 427 428
})
```



## bundle.getAllApplicationInfo

getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array\<ApplicationInfo>>): void

Z
zengyawen 已提交
429
Obtains the information about all applications of the specified user. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
430

W
wusongqing 已提交
431
**Required permissions**
W
wusongqing 已提交
432

W
wusongqing 已提交
433 434 435 436 437
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
438 439 440

**Parameters**

Z
zengyawen 已提交
441 442 443 444
| Name         | Type                                    | Mandatory  | Description                                     |
| ----------- | -------------------------------------- | ---- | --------------------------------------- |
| bundleFlags | number                                 | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId      | number                                 | No   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.           |
W
wusongqing 已提交
445
| callback    | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Yes   | Callback used to return the application information.                |
W
wusongqing 已提交
446 447 448 449

**Example**

```js
W
wusongqing 已提交
450 451 452 453 454 455 456 457 458
let bundleFlags = 8;
let userId = 100;
bundle.getAllApplicationInfo(bundleFlags, userId, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
W
wusongqing 已提交
459 460 461
```


W
wusongqing 已提交
462 463
## bundle.getAllApplicationInfo

Z
zengyawen 已提交
464
getAllApplicationInfo(bundleFlags: number, callback: AsyncCallback<Array\<ApplicationInfo>>) : void;
W
wusongqing 已提交
465

466
Obtains the information about all applications. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
467 468 469 470 471 472 473 474 475 476 477

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
478 479 480
| Name         | Type                                    | Mandatory  | Description                                     |
| ----------- | -------------------------------------- | ---- | --------------------------------------- |
| bundleFlags | number                                 | Yes   | Type of information that will be returned. The default value is **0**. The value must be greater than or equal to 0.|
W
wusongqing 已提交
481
| callback    | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Yes   | Callback used to return the application information.                |
W
wusongqing 已提交
482 483 484 485 486 487 488 489 490 491 492 493 494 495

**Example**

```js
let bundleFlags = 8;
bundle.getAllApplicationInfo(bundleFlags, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
## bundle.getBundleArchiveInfo

getBundleArchiveInfo(hapFilePath: string, bundleFlags: number) : Promise<BundleInfo>

Obtains information about the bundles contained in a HAP file. This API uses a promise to return the result.

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

| Name        | Type    | Mandatory  | Description          |
| ---------- | ------ | ---- | ------------ |
| hapFilePath | string | Yes   | Path where the HAP file is stored. The path should point to the relative directory of the current application's data directory.|
| bundleFlags | number | Yes   | Flags used to specify information contained in the **BundleInfo** object that will be returned. The default value is **0**. The value must be greater than 0.|

**Return value**
| Type            | Description                                    |
| -------------- | -------------------------------------- |
| Promise\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Promise used to return the information about the bundles.|

**Example**

```js
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = 0;
bundle.getBundleArchiveInfo(hapFilePath, bundleFlags)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```

## bundle.getBundleArchiveInfo

getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback<BundleInfo>) : void

Obtains information about the bundles contained in a HAP file. This API uses an asynchronous callback to return the result.

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

| Name        | Type    | Mandatory  | Description          |
| ---------- | ------ | ---- | ------------ |
| hapFilePath | string | Yes   | Path where the HAP file is stored. The path should point to the relative directory of the current application's data directory.|
| bundleFlags | number | Yes   | Flags used to specify information contained in the **BundleInfo** object that will be returned. The default value is **0**. The value must be greater than 0.|
| callback| AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes   | Flags used to specify information contained in the **BundleInfo** object that will be returned. The default value is **0**. The value must be greater than 0.|

**Example**

```js
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = 0;
bundle.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
563 564 565 566
## bundle.getAbilityInfo

getAbilityInfo(bundleName: string, abilityName: string): Promise\<AbilityInfo>

Z
zengyawen 已提交
567
Obtains the ability information based on a given bundle name and ability name. This API uses a promise to return the result.
W
wusongqing 已提交
568 569 570 571 572 573 574 575 576 577 578

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
579 580 581 582
| Name         | Type    | Mandatory  | Description              |
| ----------- | ------ | ---- | ---------------- |
| bundleName  | string | Yes   | Bundle name of the application.    |
| abilityName | string | Yes   | Ability name.|
W
wusongqing 已提交
583 584 585

**Return value**

Z
zengyawen 已提交
586 587
| Type                   | Description                   |
| --------------------- | --------------------- |
W
wusongqing 已提交
588
| Promise\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Promise used to return the ability information.|
W
wusongqing 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604

**Example**

```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityInfo(bundleName, abilityName)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```

## bundle.getAbilityInfo

Z
zengyawen 已提交
605
getAbilityInfo(bundleName: string, abilityName: string, callback: AsyncCallback\<AbilityInfo>): void;
W
wusongqing 已提交
606

Z
zengyawen 已提交
607
Obtains the ability information based on a given bundle name and ability name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
608 609 610 611 612 613 614 615 616 617 618

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
619 620 621 622
| Name        | Type    | Mandatory  | Description           |
| ----------- | ------------ | ---- | ---------------- |
| bundleName  | string | Yes   | Bundle name of the application.    |
| abilityName | string | Yes   | Ability name.|
W
wusongqing 已提交
623
| callback    | AsyncCallback\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes   | Callback used to return the ability information.|
W
wusongqing 已提交
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638

**Example**

```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityInfo(bundleName, abilityName, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
639
## bundle.getAbilityLabel<sup>8+</sup>
W
wusongqing 已提交
640 641 642

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

Z
zengyawen 已提交
643
Obtains the application name based on a given bundle name and ability name. This API uses a promise to return the result.
W
wusongqing 已提交
644 645 646 647 648 649 650 651 652 653 654

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
655 656 657 658
| Name         | Type    | Mandatory  | Description              |
| ----------- | ------ | ---- | ---------------- |
| bundleName  | string | Yes   | Bundle name of the application.    |
| abilityName | string | Yes   | Ability name.|
W
wusongqing 已提交
659 660 661

**Return value**

Z
zengyawen 已提交
662 663
| Type              | Description                |
| ---------------- | ------------------ |
W
wusongqing 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
| Promise\<string> | Promise used to return the application name.|

**Example**

```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityLabel(bundleName, abilityName)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```

W
wusongqing 已提交
679
## bundle.getAbilityLabel<sup>8+</sup>
W
wusongqing 已提交
680 681 682

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

Z
zengyawen 已提交
683
Obtains the application name based on a given bundle name and ability name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
684 685 686 687 688 689 690 691 692 693 694

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
695 696 697 698 699
| Name         | Type                    | Mandatory  | Description              |
| ----------- | ---------------------- | ---- | ---------------- |
| bundleName  | string                 | Yes   | Bundle name of the application.    |
| abilityName | string                 | Yes   | Ability name.|
| callback    | AsyncCallback\<string> | Yes   | Callback used to return the application name.       |
W
wusongqing 已提交
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714

**Example**

```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityLabel(bundleName, abilityName, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
715
## bundle.isAbilityEnabled<sup>8+</sup>
W
wusongqing 已提交
716 717 718

isAbilityEnabled(info: AbilityInfo): Promise\<boolean>

W
wusongqing 已提交
719
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses a promise to return the result.
W
wusongqing 已提交
720 721 722 723 724 725 726 727 728 729 730

**Required permissions**

None

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
731 732
| Name  | Type         | Mandatory  | Description          |
| ---- | ----------- | ---- | ------------ |
W
wusongqing 已提交
733
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes   | Ability information.|
W
wusongqing 已提交
734 735 736

**Return value**

Z
zengyawen 已提交
737 738
| Type               | Description                       |
| ----------------- | ------------------------- |
W
wusongqing 已提交
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
| Promise\<boolean> | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|

**Example**

```js
let Info = {
    bundleName : "com.example.myapplication",
    name : "com.example.myapplication.MainAbility"
};
bundle.isAbilityEnabled(Info)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```

W
wusongqing 已提交
756
## bundle.isAbilityEnabled<sup>8+</sup>
W
wusongqing 已提交
757 758 759

isAbilityEnabled(info : AbilityInfo, callback : AsyncCallback\<boolean>): void

W
wusongqing 已提交
760
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
761 762 763 764 765 766 767 768 769 770 771

**Required permissions**

None

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
772 773
| Name      | Type                     | Mandatory  | Description             |
| -------- | ----------------------- | ---- | --------------- |
W
wusongqing 已提交
774
| info     | [AbilityInfo](js-apis-bundle-AbilityInfo.md)             | Yes   | Ability information.   |
Z
zengyawen 已提交
775
| callback | AsyncCallback\<boolean> | Yes   | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
W
wusongqing 已提交
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792

**Example**

```js
let Info = {
    bundleName : "com.example.myapplication",
    name : "com.example.myapplication.MainAbility"
};
bundle.isAbilityEnabled(Info, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
793
## bundle.isApplicationEnabled<sup>8+</sup>
W
wusongqing 已提交
794 795 796

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

797
Checks whether an application is enabled based on a given bundle name. This API uses a promise to return the result.
W
wusongqing 已提交
798 799 800 801 802 803 804 805 806 807 808

**Required permissions**

None

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
809 810 811
| Name        | Type    | Mandatory  | Description          |
| ---------- | ------ | ---- | ------------ |
| bundleName | string | Yes   | Bundle name of the application.|
W
wusongqing 已提交
812 813 814

**Return value**

Z
zengyawen 已提交
815 816 817
| Type               | Description                       |
| ----------------- | ------------------------- |
| Promise\<boolean> | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
W
wusongqing 已提交
818 819 820 821 822 823 824 825 826 827 828 829 830

**Example**

```js
let bundleName = "com.example.myapplication";
bundle.isApplicationEnabled(bundleName)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```

W
wusongqing 已提交
831
## bundle.isApplicationEnabled<sup>8+</sup>
W
wusongqing 已提交
832 833 834

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

W
wusongqing 已提交
835
Checks whether an application is enabled based on a given bundle name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
836 837 838 839 840 841 842 843 844 845 846

**Required permissions**

None

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

Z
zengyawen 已提交
847 848 849 850
| Name        | Type                     | Mandatory  | Description             |
| ---------- | ----------------------- | ---- | --------------- |
| bundleName | string                  | Yes   | Bundle name of the application.   |
| callback   | AsyncCallback\<boolean> | Yes   | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
W
wusongqing 已提交
851 852 853 854

**Example**

```js
Z
zengyawen 已提交
855
let bundleName = "com.example.myapplication";
W
wusongqing 已提交
856 857 858 859 860 861 862 863
bundle.isApplicationEnabled(bundleName, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
W
wusongqing 已提交
864 865 866 867 868

## bundle.queryAbilityByWant

queryAbilityByWant(want: Want, bundleFlags: number, userId?: number): Promise<Array\<AbilityInfo>>

Z
zengyawen 已提交
869
Obtains the ability information based on a given want. This API uses a promise to return the result.
W
wusongqing 已提交
870

W
wusongqing 已提交
871
**Required permissions**
W
wusongqing 已提交
872

W
wusongqing 已提交
873 874 875 876 877
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
878 879 880

**Parameters**

Z
zengyawen 已提交
881 882
| Name         | Type    | Mandatory  | Description                                   |
| ----------- | ------ | ---- | ------------------------------------- |
W
wusongqing 已提交
883
| want        | [Want](js-apis-application-Want.md)   | Yes   | Want that contains the bundle name.                    |
Z
zengyawen 已提交
884 885
| bundleFlags | number | Yes   | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId      | number | No   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.          |
W
wusongqing 已提交
886 887 888

**Return value**

Z
zengyawen 已提交
889 890
| Type                          | Description                   |
| ---------------------------- | --------------------- |
W
wusongqing 已提交
891
| Promise<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Promise used to return the ability information.|
W
wusongqing 已提交
892 893 894 895

**Example**

```js
W
wusongqing 已提交
896 897 898 899 900 901 902 903 904 905 906
let bundleFlags = 0;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, userId)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
W
wusongqing 已提交
907 908 909 910 911 912 913 914 915
})
```



## bundle.queryAbilityByWant

queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback\<Array\<AbilityInfo>>): void

Z
zengyawen 已提交
916
Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
917 918 919 920

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
921 922 923

**Parameters**

Z
zengyawen 已提交
924 925
| Name         | Type                                | Mandatory  | Description                                   |
| ----------- | ---------------------------------- | ---- | ------------------------------------- |
W
wusongqing 已提交
926 927
| want        | [Want](js-apis-application-Want.md) | Yes   | Want that contains the bundle name.                  |
| bundleFlags | number                             | Yes   | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
Z
zengyawen 已提交
928
| userId      | number                             | Yes   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.          |
W
wusongqing 已提交
929
| callback    | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes   | Callback used to return the ability information.           |
W
wusongqing 已提交
930 931 932 933

**Example**

```js
W
wusongqing 已提交
934 935 936 937 938 939 940 941 942 943 944 945 946
let bundleFlags = 0;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, userId, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
W
wusongqing 已提交
947 948 949 950
```

## bundle.queryAbilityByWant

Z
zengyawen 已提交
951
queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Array\<AbilityInfo>>): void;
W
wusongqing 已提交
952

Z
zengyawen 已提交
953
Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
954

W
wusongqing 已提交
955 956 957 958
**System capability**

SystemCapability.BundleManager.BundleFramework

W
wusongqing 已提交
959 960
**Parameters**

Z
zengyawen 已提交
961 962
| Name         | Type                                | Mandatory  | Description                                   |
| ----------- | ---------------------------------- | ---- | ------------------------------------- |
W
wusongqing 已提交
963 964 965
| want        | [Want](js-apis-application-Want.md)   | Yes   | Want that contains the bundle name.                  |
| bundleFlags | number                             | Yes   | Ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| callback    | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes   | Callback used to return the ability information.           |
W
wusongqing 已提交
966 967 968 969

**Example**

```js
W
wusongqing 已提交
970 971 972 973 974 975 976 977 978 979 980
let bundleFlags = 0;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
W
wusongqing 已提交
981 982 983 984 985
})
```



W
wusongqing 已提交
986 987 988 989
## bundle.getLaunchWantForBundle

getLaunchWantForBundle(bundleName: string): Promise\<Want>

Z
zengyawen 已提交
990
Obtains the **Want** object that launches the specified application. This API uses a promise to return the result.
W
wusongqing 已提交
991

W
wusongqing 已提交
992 993
**Required permissions**

W
wusongqing 已提交
994 995 996 997 998
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
999 1000 1001

**Parameters**

Z
zengyawen 已提交
1002 1003 1004
| Name        | Type    | Mandatory  | Description          |
| ---------- | ------ | ---- | ------------ |
| bundleName | string | Yes   | Bundle name of the application.|
W
wusongqing 已提交
1005 1006

**Return value**
Z
zengyawen 已提交
1007 1008
| Type            | Description                                    |
| -------------- | -------------------------------------- |
W
wusongqing 已提交
1009
| Promise\<[Want](js-apis-application-Want.md)> | Promise used to return the **Want** object.|
W
wusongqing 已提交
1010 1011 1012 1013

**Example**

```js
W
wusongqing 已提交
1014 1015 1016 1017 1018 1019 1020
let bundleName = "com.example.myapplication";
bundle.getLaunchWantForBundle(bundleName)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
W
wusongqing 已提交
1021 1022
```

W
wusongqing 已提交
1023
## bundle.getLaunchWantForBundle
W
wusongqing 已提交
1024

W
wusongqing 已提交
1025
getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void;
W
wusongqing 已提交
1026

Z
zengyawen 已提交
1027
Obtains the **Want** object that launches the specified application. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1028

W
wusongqing 已提交
1029
**Required permissions**
W
wusongqing 已提交
1030

W
wusongqing 已提交
1031 1032 1033 1034 1035
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1036 1037 1038

**Parameters**

Z
zengyawen 已提交
1039 1040 1041
| Name        | Type                  | Mandatory  | Description                            |
| ---------- | -------------------- | ---- | ------------------------------ |
| bundleName | string               | Yes   | Bundle name of the application.                  |
W
wusongqing 已提交
1042
| callback   | AsyncCallback\<[Want](js-apis-application-Want.md)> | Yes   | Callback used to return the **Want** object.|
W
wusongqing 已提交
1043 1044 1045 1046

**Example**

```js
W
wusongqing 已提交
1047 1048 1049 1050 1051 1052 1053 1054
let bundleName = "com.example.myapplication";
bundle.getLaunchWantForBundle(bundleName, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
W
wusongqing 已提交
1055 1056 1057
```


W
wusongqing 已提交
1058
## bundle.getNameForUid<sup>8+</sup>
W
wusongqing 已提交
1059 1060

getNameForUid(uid: number): Promise\<string>
W
wusongqing 已提交
1061

Z
zengyawen 已提交
1062
Obtains the bundle name based on a UID. This API uses a promise to return the result.
W
wusongqing 已提交
1063 1064 1065 1066

**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1067 1068 1069

**Parameters**

Z
zengyawen 已提交
1070 1071 1072
| Name  | Type    | Mandatory  | Description      |
| ---- | ------ | ---- | -------- |
| uid  | number | Yes   | UID based on which the bundle name is to obtain.|
W
wusongqing 已提交
1073 1074

**Return value**
Z
zengyawen 已提交
1075 1076
| Type              | Description                               |
| ---------------- | --------------------------------- |
W
wusongqing 已提交
1077
| Promise\<string> | Promise used to return the bundle name.|
W
wusongqing 已提交
1078 1079 1080 1081

**Example**

```js
W
wusongqing 已提交
1082 1083 1084 1085 1086 1087 1088
let uid = 20010005;
bundle.getNameForUid(uid)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
W
wusongqing 已提交
1089 1090
```

W
wusongqing 已提交
1091
## bundle.getNameForUid<sup>8+</sup>
W
wusongqing 已提交
1092

Z
zengyawen 已提交
1093
getNameForUid(uid: number, callback: AsyncCallback\<string>) : void
W
wusongqing 已提交
1094

Z
zengyawen 已提交
1095
Obtains the bundle name based on a UID. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1096

W
wusongqing 已提交
1097 1098 1099
**System capability**

SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1100 1101 1102

**Parameters**

Z
zengyawen 已提交
1103 1104 1105 1106
| Name      | Type                    | Mandatory  | Description                       |
| -------- | ---------------------- | ---- | ------------------------- |
| uid      | number                 | Yes   | UID based on which the bundle name is to obtain.                 |
| callback | AsyncCallback\<string> | Yes   | Callback used to return the bundle name.|
W
wusongqing 已提交
1107 1108 1109 1110

**Example**

```js
W
wusongqing 已提交
1111 1112 1113 1114 1115 1116 1117 1118
let uid = 20010005;
bundle.getNameForUid(uid, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
W
wusongqing 已提交
1119 1120
```

W
wusongqing 已提交
1121

W
wusongqing 已提交
1122
## bundle.getAbilityIcon<sup>8+</sup>
W
wusongqing 已提交
1123

Z
zengyawen 已提交
1124
getAbilityIcon(bundleName: string, abilityName: string): Promise\<image.PixelMap>;
W
wusongqing 已提交
1125

W
wusongqing 已提交
1126
Obtains the [PixelMap](js-apis-image.md) of the icon corresponding to a given bundle name and ability name. This API uses a promise to return the result.
W
wusongqing 已提交
1127

W
wusongqing 已提交
1128 1129 1130 1131 1132 1133 1134 1135
**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

W
wusongqing 已提交
1136 1137
**Parameters**

Z
zengyawen 已提交
1138 1139 1140 1141
| Name         | Type                                      | Mandatory  | Description                                      |
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName  | string                                   | Yes   | Bundle name based on which the pixel map is to obtain.                         |
| abilityName | string                                   | Yes   | Ability name based on which the pixel map is to obtain.                        |
W
wusongqing 已提交
1142 1143 1144 1145

**Return value**
| Type                 | Description                                                        |
| --------------------- | ------------------------------------------------------------ |
W
wusongqing 已提交
1146
| Promise\<image.PixelMap> | Promise used to return the [PixelMap](js-apis-image.md).|
W
wusongqing 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160

**Example**

```js
let bundleName = com.example.myapplication;
let abilityName = com.example.myapplication.MainAbility;
bundle.getAbilityIcon(bundleName, abilityName)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```

W
wusongqing 已提交
1161
## bundle.getAbilityIcon<sup>8+</sup>
W
wusongqing 已提交
1162

Z
zengyawen 已提交
1163
getAbilityIcon(bundleName: string, abilityName: string, callback: AsyncCallback\<image.PixelMap>): void;
W
wusongqing 已提交
1164

W
wusongqing 已提交
1165
Obtains the [PixelMap](js-apis-image.md) of the icon corresponding to a given bundle name and ability name. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1166

W
wusongqing 已提交
1167 1168 1169 1170 1171 1172 1173 1174
**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

W
wusongqing 已提交
1175 1176
**Parameters**

Z
zengyawen 已提交
1177 1178 1179 1180
| Name         | Type                                      | Mandatory  | Description                                      |
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName  | string                                   | Yes   | Bundle name based on which the pixel map is to obtain.                         |
| abilityName | string                                   | Yes   | Ability name based on which the pixel map is to obtain.                        |
W
wusongqing 已提交
1181
| callback   | AsyncCallback\<image.PixelMap> | Yes  | Callback used to return the [PixelMap](js-apis-image.md).|
W
wusongqing 已提交
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196

**Example**

```js
let bundleName = com.example.myapplication;
let abilityName = com.example.myapplication.MainAbility;
bundle.getAbilityIcon(bundleName, abilityName, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

W
wusongqing 已提交
1197

W
wusongqing 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
## bundle.queryExtensionAbilityInfosByWant<sup>9+</sup>

queryExtensionAbilityInfosByWant(want: Want, extensionFlags: number, userId?: number): Promise<Array\<ExtensionAbilityInfo>>

Obtains the Extension ability information based on a given want. This API uses a promise to return the result.

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

| Name            | Type    | Mandatory  | Description                                      |
| -------------- | ------ | ---- | ---------------------------------------- |
| want           | [Want](js-apis-application-Want.md)   | Yes   | Want that contains the bundle name.                       |
| extensionFlags | number | Yes   | Extension ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId         | number | No   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.             |

**Return value**

| Type                                   | Description                            |
| ------------------------------------- | ------------------------------ |
| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Promise used to return the Extension ability information.|

**Example**

```js
let extensionFlags = 0;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryExtensionAbilityInfosByWant(want, extensionFlags, userId)
.then((data) => {
    console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
    console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```



## bundle.queryExtensionAbilityInfosByWant<sup>9+</sup>

queryExtensionAbilityInfosByWant(want: Want, extensionFlags: number, userId: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void

Obtains the Extension ability information based on a given want. This API uses an asynchronous callback to return the result.

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO

**System capability**
W
wusongqing 已提交
1256

W
wusongqing 已提交
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323
SystemCapability.BundleManager.BundleFramework

**Parameters**

| Name            | Type                                      | Mandatory  | Description                                      |
| -------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| want           | [Want](js-apis-application-Want.md)      | Yes   | Want that contains the bundle name.                     |
| extensionFlags | number                                   | Yes   | Extension ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| userId         | number                                   | Yes   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.             |
| callback       | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes   | Callback used to return the Extension ability information.     |

**Example**

```js
let extensionFlags = 0;
let userId = 100;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryExtensionAbilityInfosByWant(want, extensionFlags, userId, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```

## bundle.queryExtensionAbilityInfosByWant<sup>9+</sup>

queryExtensionAbilityInfosByWant(want: Want, extensionFlags: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void;

Obtains the Extension ability information based on a given want. This API uses an asynchronous callback to return the result.

**Required permissions**

ohos.permission.GET_BUNDLE_INFO_PRIVILEGED, ohos.permission.GET_BUNDLE_INFO

**System capability**

SystemCapability.BundleManager.BundleFramework

**Parameters**

| Name            | Type                                      | Mandatory  | Description                                      |
| -------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| want           | [Want](js-apis-application-Want.md)      | Yes   | Want that contains the bundle name.                     |
| extensionFlags | number                                   | Yes   | Extension ability information to be returned. The default value is **0**. The value must be greater than or equal to 0.|
| callback       | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes   | Callback used to return the Extension ability information.     |

**Example**

```js
let extensionFlags = 0;
let want = {
    bundleName : "com.example.myapplication",
    abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryExtensionAbilityInfosByWant(want, extensionFlags, (err, data) => {
    if (err) {
        console.error('Operation failed. Cause: ' + JSON.stringify(err));
        return;
    }
    console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
W
wusongqing 已提交
1324

W
wusongqing 已提交
1325
## InstallErrorCode
W
wusongqing 已提交
1326

W
wusongqing 已提交
1327 1328
 **System capability**: SystemCapability.BundleManager.BundleFramework

Z
zengyawen 已提交
1329 1330 1331
| Name                                      | Default Value | Description                       |
| ---------------------------------------- | ---- | ------------------------- |
| SUCCESS                                  | 0    | Installation succeeded.                     |
1332
| STATUS_INSTALL_FAILURE                   | 1    | Installation failed. (The application to be installed is not found.)           |
Z
zengyawen 已提交
1333 1334
| STATUS_INSTALL_FAILURE_ABORTED           | 2    | Installation aborted.                     |
| STATUS_INSTALL_FAILURE_INVALID           | 3    | Invalid installation parameter.                   |
1335
| STATUS_INSTALL_FAILURE_CONFLICT          | 4    | Installation conflict. (The basic information of the application to update is inconsistent with that of the existing application.) |
Z
zengyawen 已提交
1336
| STATUS_INSTALL_FAILURE_STORAGE           | 5    | Failed to store the bundle information.                  |
1337 1338
| STATUS_INSTALL_FAILURE_INCOMPATIBLE      | 6    | Installation incompatibility. (A downgrade occurs or the signature information is incorrect.) |
| STATUS_UNINSTALL_FAILURE                 | 7    | Uninstallation failed. (The application to be uninstalled is not found.)          |
Z
zengyawen 已提交
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
| STATUS_UNINSTALL_FAILURE_BLOCKED         | 8    | Uninstallation aborted. (This error code is not in use.)              |
| STATUS_UNINSTALL_FAILURE_ABORTED         | 9    | Uninstallation aborted. (Invalid parameters.)            |
| STATUS_UNINSTALL_FAILURE_CONFLICT        | 10   | Uninstallation conflict. (Failed to uninstall a system application or end the application process.)|
| STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT  | 0x0B | Installation failed. (Download timed out.)              |
| STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED   | 0x0C | Installation failed. (Download failed.)              |
| STATUS_RECOVER_FAILURE_INVALID<sup>8+</sup> | 0x0D | Failed to restore the pre-installed application.                 |
| STATUS_ABILITY_NOT_FOUND                 | 0x40 | Ability not found.               |
| STATUS_BMS_SERVICE_ERROR                 | 0x41 | BMS service error.                  |
| STATUS_FAILED_NO_SPACE_LEFT<sup>8+</sup> | 0x42 | Insufficient device space.                   |
| STATUS_GRANT_REQUEST_PERMISSIONS_FAILED<sup>8+</sup> | 0x43 | Application authorization failed.                   |
| STATUS_INSTALL_PERMISSION_DENIED<sup>8+</sup> | 0x44 | Installation permission denied.                   |
| STATUS_UNINSTALL_PERMISSION_DENIED<sup>8+</sup> | 0x45 | Uninstallation permission denied.                   |
W
wusongqing 已提交
1351 1352 1353

## BundleFlag

W
wusongqing 已提交
1354 1355 1356
Enumerates bundle flags.

 **System capability**: SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1357

Z
zengyawen 已提交
1358 1359 1360 1361 1362 1363 1364 1365 1366
| Name                                      | Default Value       | Description                 |
| ---------------------------------------- | ---------- | ------------------- |
| GET_BUNDLE_DEFAULT                       | 0x00000000 | Obtains the default application information.          |
| GET_BUNDLE_WITH_ABILITIES                | 0x00000001 | Obtains the bundle information with the ability information.  |
| GET_ABILITY_INFO_WITH_PERMISSION         | 0x00000002 | Obtains the ability information with the permission information.   |
| GET_ABILITY_INFO_WITH_APPLICATION        | 0x00000004 | Obtains the ability information with the application information.   |
| GET_APPLICATION_INFO_WITH_PERMISSION     | 0x00000008 | Obtains the application information with the permission information.        |
| GET_BUNDLE_WITH_REQUESTED_PERMISSION     | 0x00000010 | Obtains the bundle information with the information about the required permissions.       |
| GET_ABILITY_INFO_WITH_METADATA<sup>8+</sup> | 0x00000020 | Obtains the ability metadata information.    |
W
wusongqing 已提交
1367
| GET_BUNDLE_WITH_EXTENSION_ABILITY<sup>9+</sup> | 0x00000020 | Obtains the bundle information with the Extension ability information.|
Z
zengyawen 已提交
1368
| GET_APPLICATION_INFO_WITH_METADATA<sup>8+</sup> | 0x00000040 | Obtains the application metadata information.         |
1369
| GET_ABILITY_INFO_SYSTEMAPP_ONLY<sup>8+</sup> | 0x00000080 | Obtains the ability information of system applications.|
Z
zengyawen 已提交
1370 1371 1372
| GET_ABILITY_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000100 | Obtains information about disabled abilities.  |
| GET_APPLICATION_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000200 | Obtains information about disabled applications.       |
| GET_ALL_APPLICATION_INFO                 | 0xFFFF0000 | Obtains all application information.          |
W
wusongqing 已提交
1373 1374 1375 1376 1377

## BundleOptions

Describes the bundle options.

W
wusongqing 已提交
1378 1379
 **System capability**: SystemCapability.BundleManager.BundleFramework

Z
zengyawen 已提交
1380 1381 1382
| Name    | Type    | Readable  | Writable  | Description                          |
| ------ | ------ | ---- | ---- | ---------------------------- |
| userId | number | Yes   | Yes   | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
W
wusongqing 已提交
1383 1384 1385 1386


## AbilityType

W
wusongqing 已提交
1387 1388 1389
Enumerates ability types.

 **System capability**: SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1390

Z
zengyawen 已提交
1391 1392 1393 1394 1395 1396
| Name     | Type  | Description               |
| ------- | ---- | ----------------- |
| UNKNOWN | None   | Unknown ability type.      |
| PAGE    | None   | Ability that has a UI.   |
| SERVICE | None   | Ability that does not have a UI.    |
| DATA    | None   | Ability that is used to provide data access services.|
W
wusongqing 已提交
1397 1398 1399

## DisplayOrientation

W
wusongqing 已提交
1400 1401 1402
Enumerates display orientations.

 **System capability**: SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1403

Z
zengyawen 已提交
1404 1405 1406 1407 1408 1409
| Name           | Type  | Description           |
| ------------- | ---- | ------------- |
| UNSPECIFIED   | None   | The system automatically determines the display orientation.    |
| LANDSCAPE     | None   | Landscape orientation.     |
| PORTRAIT      | None   | Portrait orientation.     |
| FOLLOW_RECENT | None   | The page ability orientation is the same as that of the nearest ability in the stack.|
W
wusongqing 已提交
1410 1411 1412

## LaunchMode

W
wusongqing 已提交
1413 1414 1415
Enumerates launch modes.

 **System capability**: SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1416

Z
zengyawen 已提交
1417 1418 1419 1420
| Name       | Type  | Description           |
| --------- | ---- | ------------- |
| SINGLETON | 0    | The ability has only one instance.|
| STANDARD  | 1    | The ability can have multiple instances. |
W
wusongqing 已提交
1421 1422 1423

## AbilitySubType

W
wusongqing 已提交
1424 1425 1426
Enumerates ability subtypes.

 **System capability**: SystemCapability.BundleManager.BundleFramework
W
wusongqing 已提交
1427

Z
zengyawen 已提交
1428 1429 1430
| Name         | Type  | Description                  |
| ----------- | ---- | -------------------- |
| UNSPECIFIED | 0    | Undefined ability subtype.       |
W
wusongqing 已提交
1431
| CA          | 1    | Ability that has a UI.|
W
wusongqing 已提交
1432

W
wusongqing 已提交
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
## ExtensionAbilityType<sup>9+</sup>

Enumerates Extension ability types.

 **System capability**: SystemCapability.BundleManager.BundleFramework

| Name                            | Type  | Description                       |
| ------------------------------ | ---- | ------------------------- |
| FORM<sup>9+</sup>              | 0    | Form included.  |
| WORK_SCHEDULER<sup>9+</sup>    | 1    | Work scheduler included.|
| INPUT_METHOD<sup>9+</sup>      | 2    | Input method included. |
| SERVICE<sup>9+</sup>           | 3    | Service included.  |
| ACCESSIBILITY<sup>9+</sup>     | 4    | Accessibility included. |
| DATA_SHARE<sup>9+</sup>        | 5    | Data sharing included.|
| FILE_SHARE<sup>9+</sup>        | 6    | File sharing included.|
| STATIC_SUBSCRIBER<sup>9+</sup> | 7    | Subscribers included. |
| WALLPAPER<sup>9+</sup>         | 8    | Wallpaper included.  |
| UNSPECIFIED<sup>9+</sup>       | 9    | Unspecified type.    |

## ExtensionFlag<sup>9+</sup>

Enumerates Extension flags.

 **System capability**: SystemCapability.BundleManager.BundleFramework

| Name                                      | Default Value       | Description                            |
| ---------------------------------------- | ---------- | ------------------------------ |
| GET_EXTENSION_INFO_DEFAULT<sup>9+</sup>  | 0x00000000 | Obtains the default Extension ability information.     |
| GET_EXTENSION_INFO_WITH_PERMISSION<sup>9+</sup> | 0x00000002 | Obtains the Extension ability information that carries permission information. |
| GET_EXTENSION_INFO_WITH_APPLICATION<sup>9+</sup> | 0x00000004 | Obtains the Extension ability information that carries application information. |
| GET_EXTENSION_INFO_WITH_METADATA<sup>9+</sup> | 0x00000020 | Obtains the Extension ability information that carries metadata information.|
W
wusongqing 已提交
1464

W
wusongqing 已提交
1465 1466 1467 1468 1469 1470
## ColorMode

Enumerates color modes.

 **System capability**: SystemCapability.BundleManager.BundleFramework

Z
zengyawen 已提交
1471 1472 1473 1474 1475
| Name        | Type  | Description  |
| ---------- | ---- | ---- |
| AUTO_MODE  | -1   | Automatic mode.|
| DARK_MODE  | 0    | Dark mode.|
| LIGHT_MODE | 1    | Light mode.|
W
wusongqing 已提交
1476

W
wusongqing 已提交
1477 1478
## GrantStatus

1479
Enumerates permission grant states.
W
wusongqing 已提交
1480 1481 1482

 **System capability**: SystemCapability.BundleManager.BundleFramework

Z
zengyawen 已提交
1483 1484 1485 1486
| Name                | Type  | Description  |
| ------------------ | ---- | ---- |
| PERMISSION_DENIED  | -1   | Permission denied.|
| PERMISSION_GRANTED | 0    | Permission granted.  |