js-apis-enterprise-bundleManager.md 79.4 KB
Newer Older
G
Gloria 已提交
1 2
# @ohos.enterprise.bundleManager (Bundle Management)

A
Annie_wang 已提交
3
The **bundleManager** module provides APIs for bundle management, including adding, obtaining, and removing a list of bundles that are allowed to install.
G
Gloria 已提交
4 5 6

> **NOTE**
>
A
Annie_wang 已提交
7
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
A
Annie_wang 已提交
8
>
A
Annie_wang 已提交
9
> - The APIs of this module can be used only in the stage model.
A
Annie_wang 已提交
10 11
>
> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
G
Gloria 已提交
12 13 14 15 16 17 18 19 20 21 22

## Modules to Import

```js
import bundleManager from '@ohos.enterprise.bundleManager';
```

## bundleManager.addAllowedInstallBundles

addAllowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
23
Adds the applications that can be installed by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
24 25 26 27 28 29 30 31 32 33 34

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
35
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
36
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
A
Annie_wang 已提交
37
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
G
Gloria 已提交
38 39 40 41 42

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
43
| ID| Error Message                                                                      |
G
Gloria 已提交
44
| ------- | ---------------------------------------------------------------------------- |
45 46
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
47

A
Annie_wang 已提交
48
**Example**
G
Gloria 已提交
49 50 51

```js
let wantTemp = {
A
Annie_wang 已提交
52 53
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
54
};
A
Annie_wang 已提交
55 56 57 58 59 60 61 62
let appIds = ['com.example.myapplication'];

bundleManager.addAllowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding allowed install bundles');
G
Gloria 已提交
63 64 65 66 67 68 69
});
```

## bundleManager.addAllowedInstallBundles

addAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
70
Adds the applications that can be installed by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
71 72 73 74 75 76 77 78 79 80 81

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
82
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
83 84
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
85
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
G
Gloria 已提交
86 87 88 89 90

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
91
| ID| Error Message                                                                    |
G
Gloria 已提交
92
| ------- | ---------------------------------------------------------------------------- |
93 94
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
95

A
Annie_wang 已提交
96
**Example**
G
Gloria 已提交
97 98 99

```js
let wantTemp = {
A
Annie_wang 已提交
100 101
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
102
};
A
Annie_wang 已提交
103 104 105 106 107 108 109 110
let appIds = ['com.example.myapplication'];

bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding allowed install bundles');
G
Gloria 已提交
111 112 113 114 115 116 117
});
```

## bundleManager.addAllowedInstallBundles

addAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;

A
Annie_wang 已提交
118
Adds the applications that can be installed by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
G
Gloria 已提交
119 120 121 122 123 124 125 126 127 128 129

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
130
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
131 132
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
| userId     | number                             | No   |User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications can be installed by the specified user.<br> - If **userId** is not passed in, the applications can be installed by the current user.|
G
Gloria 已提交
133 134 135 136 137

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
138
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
G
Gloria 已提交
139 140 141 142 143

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
144
| ID| Error Message                                                                    |
G
Gloria 已提交
145
| ------- | ---------------------------------------------------------------------------- |
146 147
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
148

A
Annie_wang 已提交
149
**Example**
G
Gloria 已提交
150 151 152

```js
let wantTemp = {
A
Annie_wang 已提交
153 154
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
155
};
A
Annie_wang 已提交
156
let appIds = ['com.example.myapplication'];
G
Gloria 已提交
157 158

bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
A
Annie_wang 已提交
159 160 161
  console.info('Succeeded in adding allowed install bundles');
}).catch((err) => {
  console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
G
Gloria 已提交
162 163 164 165 166 167 168
});
```

## bundleManager.removeAllowedInstallBundles

removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
169
Removes the applications that can be installed by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
170 171 172 173 174 175 176 177 178 179 180

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
181
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
182
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
A
Annie_wang 已提交
183
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
G
Gloria 已提交
184 185 186 187 188

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
189
| ID| Error Message                                                                      |
G
Gloria 已提交
190
| ------- | ---------------------------------------------------------------------------- |
191 192
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
193

A
Annie_wang 已提交
194
**Example**
G
Gloria 已提交
195 196 197

```js
let wantTemp = {
A
Annie_wang 已提交
198 199
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
200
};
A
Annie_wang 已提交
201 202 203 204 205 206 207 208
let appIds = ['com.example.myapplication'];

bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing allowed install bundles');
G
Gloria 已提交
209 210 211 212 213 214 215
});
```

## bundleManager.removeAllowedInstallBundles

removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
216
Removes the applications that can be installed by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
217 218 219 220 221 222 223 224 225 226 227

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
228
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
229 230
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
231
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
G
Gloria 已提交
232 233 234 235 236

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
237
| ID| Error Message                                                                    |
G
Gloria 已提交
238
| ------- | ---------------------------------------------------------------------------- |
239 240
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
241

A
Annie_wang 已提交
242
**Example**
G
Gloria 已提交
243 244 245

```js
let wantTemp = {
A
Annie_wang 已提交
246 247
    bundleName: 'com.example.myapplication',
    abilityName: 'EntryAbility',
G
Gloria 已提交
248
};
A
Annie_wang 已提交
249 250 251 252 253 254 255 256
let appIds = ['com.example.myapplication'];

bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing allowed install bundles');
G
Gloria 已提交
257 258 259 260 261 262 263
});
```

## bundleManager.removeAllowedInstallBundles

removeAllowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;

A
Annie_wang 已提交
264
Removes the applications that can be installed by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
G
Gloria 已提交
265 266 267 268 269 270 271 272 273 274 275

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
276
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
277 278
| appIds    | Array\&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications can be installed by the specified user.<br> - If **userId** is not passed in, the applications can be installed by the current user.|
G
Gloria 已提交
279 280 281 282 283

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
284
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
G
Gloria 已提交
285 286 287 288 289

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
290
| ID| Error Message                                                                    |
G
Gloria 已提交
291
| ------- | ---------------------------------------------------------------------------- |
292 293
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
294

A
Annie_wang 已提交
295
**Example**
G
Gloria 已提交
296 297 298

```js
let wantTemp = {
A
Annie_wang 已提交
299 300
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
301
};
A
Annie_wang 已提交
302
let appIds = ['com.example.myapplication'];
G
Gloria 已提交
303 304

bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
A
Annie_wang 已提交
305 306 307
  console.info('Succeeded in removing allowed install bundles');
}).catch((err) => {
  console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
G
Gloria 已提交
308 309 310 311 312 313 314
});
```

## bundleManager.getAllowedInstallBundles

getAllowedInstallBundles(admin: Want, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;

A
Annie_wang 已提交
315
Obtains the applications that can be installed by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
316 317 318 319 320 321 322 323 324 325 326

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
327 328
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
G
Gloria 已提交
329 330 331 332 333

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
334
| ID| Error Message                                                                      |
G
Gloria 已提交
335
| ------- | ---------------------------------------------------------------------------- |
336 337
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
338

A
Annie_wang 已提交
339
**Example**
G
Gloria 已提交
340 341 342

```js
let wantTemp = {
A
Annie_wang 已提交
343 344
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
345 346
};

A
Annie_wang 已提交
347 348 349 350 351 352
bundleManager.getAllowedInstallBundles(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
G
Gloria 已提交
353 354 355 356 357 358 359
});
```

## bundleManager.getAllowedInstallBundles

getAllowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;

A
Annie_wang 已提交
360
Obtains the applications that can be installed by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
361 362 363 364 365 366 367 368 369 370 371

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
372
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
373
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
374
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
G
Gloria 已提交
375 376 377 378 379

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
380
| ID| Error Message                                                                      |
G
Gloria 已提交
381
| ------- | ---------------------------------------------------------------------------- |
382 383
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
384

A
Annie_wang 已提交
385
**Example**
G
Gloria 已提交
386 387 388

```js
let wantTemp = {
A
Annie_wang 已提交
389 390
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
391 392
};

A
Annie_wang 已提交
393 394 395 396 397 398
bundleManager.getAllowedInstallBundles(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
G
Gloria 已提交
399 400 401 402 403 404 405
});
```

## bundleManager.getAllowedInstallBundles

getAllowedInstallBundles(admin: Want, userId?: number): Promise&lt;Array&lt;string&gt;&gt;;

A
Annie_wang 已提交
406
Obtains the applications that can be installed by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
G
Gloria 已提交
407 408 409 410 411 412 413 414 415 416 417

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
418
| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
A
Annie_wang 已提交
419
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications can be installed by the specified user.<br> - If **userId** is not passed in, the applications can be installed by the current user.|
G
Gloria 已提交
420 421 422 423 424

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
425
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the list of the bundles obtained.|
G
Gloria 已提交
426 427 428 429 430

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
431
| ID| Error Message                                                                    |
G
Gloria 已提交
432
| ------- | ---------------------------------------------------------------------------- |
433 434
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
G
Gloria 已提交
435

A
Annie_wang 已提交
436
**Example**
G
Gloria 已提交
437 438 439

```js
let wantTemp = {
A
Annie_wang 已提交
440 441
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
G
Gloria 已提交
442
};
A
Annie_wang 已提交
443 444 445 446 447

bundleManager.getAllowedInstallBundles(wantTemp, 100).then((result) => {
  console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
}).catch((err) => {
  console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
G
Gloria 已提交
448 449
});
```
450 451 452 453 454

## bundleManager.addDisallowedInstallBundles

addDisallowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
455
Adds the applications that cannot be installed by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
456 457 458 459 460 461 462 463 464 465 466

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
467
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
468
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
A
Annie_wang 已提交
469
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
470 471 472 473 474

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
475
| ID| Error Message                                                                      |
476 477 478 479
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
480
**Example**
481 482 483

```js
let wantTemp = {
A
Annie_wang 已提交
484 485
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
486
};
A
Annie_wang 已提交
487 488 489 490 491 492 493 494
let appIds = ['com.example.myapplication'];

bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed install bundles');
495 496 497 498 499 500 501
});
```

## bundleManager.addDisallowedInstallBundles

addDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
502
Adds the applications that cannot be installed by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
503 504 505 506 507 508 509 510 511 512 513

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
514
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
515 516
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
517
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
518 519 520 521 522

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
523
| ID| Error Message                                                                    |
524 525 526 527
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
528
**Example**
529 530 531

```js
let wantTemp = {
A
Annie_wang 已提交
532 533
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
534
};
A
Annie_wang 已提交
535 536 537 538 539 540 541 542
let appIds = ['com.example.myapplication'];

bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed install bundles');
543 544 545 546 547 548 549
});
```

## bundleManager.addDisallowedInstallBundles

addDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;

A
Annie_wang 已提交
550
Adds the applications that cannot be installed by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
551 552 553 554 555 556 557 558 559 560 561

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
562
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
563 564
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be installed by the specified user.<br> - If **userId** is not passed in, the applications cannot be installed by the current user.|
565 566 567 568 569

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
570
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
571 572 573 574 575

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
576
| ID| Error Message                                                                    |
577 578 579 580
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
581
**Example**
582 583 584

```js
let wantTemp = {
A
Annie_wang 已提交
585 586
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
587
};
A
Annie_wang 已提交
588
let appIds = ['com.example.myapplication'];
589 590

bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
A
Annie_wang 已提交
591 592 593
  console.info('Succeeded in adding disallowed install bundles');
}).catch((err) => {
  console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
594 595 596 597 598 599 600
});
```

## bundleManager.removeDisallowedInstallBundles

removeDisallowedInstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;

A
Annie_wang 已提交
601
Removes the applications that cannot be installed by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
602 603 604 605 606 607 608 609 610 611 612

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
613
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
614
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
A
Annie_wang 已提交
615
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
616 617 618 619 620

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
621
| ID| Error Message                                                                      |
622 623 624 625
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
626
**Example**
627 628 629

```js
let wantTemp = {
A
Annie_wang 已提交
630 631
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
632
};
A
Annie_wang 已提交
633 634 635 636 637 638 639 640
let appIds = ['com.example.myapplication'];

bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed install bundles');
641 642 643 644 645
});
```

## bundleManager.removeDisallowedInstallBundles

A
Annie_wang 已提交
646
removeDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;
647

A
Annie_wang 已提交
648
Removes the applications that cannot be installed by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
649 650 651 652 653 654 655 656 657 658 659

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
660
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
661 662
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
663
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
664 665 666 667 668

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
669
| ID| Error Message                                                                    |
670 671 672 673
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
674
**Example**
675 676 677

```js
let wantTemp = {
A
Annie_wang 已提交
678 679
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
680
};
A
Annie_wang 已提交
681 682 683 684 685 686 687 688
let appIds = ['com.example.myapplication'];

bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed install bundles');
689 690 691 692 693 694 695
});
```

## bundleManager.removeDisallowedInstallBundles

removeDisallowedInstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;

A
Annie_wang 已提交
696
Removes the applications that cannot be installed by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
697 698 699 700 701 702 703 704 705 706 707

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
708
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
709 710
| appIds    | Array\&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be installed by the specified user.<br> - If **userId** is not passed in, the applications cannot be installed by the current user.|
711 712 713 714 715

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
716
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
717 718 719 720 721

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
722
| ID| Error Message                                                                    |
723 724 725 726
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
727
**Example**
728 729 730

```js
let wantTemp = {
A
Annie_wang 已提交
731 732
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
733
};
A
Annie_wang 已提交
734
let appIds = ['com.example.myapplication'];
735 736

bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
A
Annie_wang 已提交
737 738 739
  console.info('Succeeded in removing disallowed install bundles');
}).catch((err) => {
  console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
740 741 742 743 744 745 746
});
```

## bundleManager.getDisallowedInstallBundles

getDisallowedInstallBundles(admin: Want, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;

A
Annie_wang 已提交
747
Obtains the applications that cannot be installed by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
748 749 750 751 752 753 754 755 756 757 758

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
759 760
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
761 762 763 764 765

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
766
| ID| Error Message                                                                      |
767 768 769 770
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
771
**Example**
772 773 774

```js
let wantTemp = {
A
Annie_wang 已提交
775 776
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
777 778
};

A
Annie_wang 已提交
779 780 781 782 783 784
bundleManager.getDisallowedInstallBundles(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
785 786 787 788 789 790 791
});
```

## bundleManager.getDisallowedInstallBundles

getDisallowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;

A
Annie_wang 已提交
792
Obtains the applications that cannot be installed by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
793 794 795 796 797 798 799 800 801 802 803

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
A
Annie_wang 已提交
804
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
805
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
806
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
807 808 809 810 811

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
812
| ID| Error Message                                                                      |
813 814 815 816
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
817
**Example**
818 819 820

```js
let wantTemp = {
A
Annie_wang 已提交
821 822
    bundleName: 'com.example.myapplication',
    abilityName: 'EntryAbility',
823 824
};

A
Annie_wang 已提交
825 826 827 828 829 830
bundleManager.getDisallowedInstallBundles(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
831 832 833 834 835 836 837
});
```

## bundleManager.getDisallowedInstallBundles

getDisallowedInstallBundles(admin: Want, userId?: number): Promise&lt;Array&lt;string&gt;&gt;;

A
Annie_wang 已提交
838
Obtains the applications that cannot be installed by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
839 840 841 842 843 844 845 846 847 848 849

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
A
Annie_wang 已提交
850
| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
A
Annie_wang 已提交
851
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be installed by the specified user.<br> - If **userId** is not passed in, the applications cannot be installed by the current user.|
852 853 854 855 856

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
857
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the list of the bundles obtained.|
858 859 860 861 862

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

A
Annie_wang 已提交
863
| ID| Error Message                                                                    |
864 865 866 867
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

A
Annie_wang 已提交
868
**Example**
869

A
Annie_wang 已提交
870
```js
871
let wantTemp = {
A
Annie_wang 已提交
872 873
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
874
};
A
Annie_wang 已提交
875 876 877 878 879

bundleManager.getDisallowedInstallBundles(wantTemp, 100).then((result) => {
  console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
}).catch((err) => {
  console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
880
});
A
Annie_wang 已提交
881
```
A
Annie_wang 已提交
882 883 884 885 886

## bundleManager.addDisallowedUninstallBundles

addDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
887
Adds the applications that cannot be uninstalled by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
888 889 890 891 892 893 894 895 896 897 898 899

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
900
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
A
Annie_wang 已提交
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
916 917
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
918
};
A
Annie_wang 已提交
919 920 921 922 923 924 925 926
let appIds = ['com.example.myapplication'];

bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed uninstall bundles');
A
Annie_wang 已提交
927 928 929 930 931 932 933
});
```

## bundleManager.addDisallowedUninstallBundles

addDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
934
Adds the applications that cannot be uninstalled by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
935 936 937 938 939 940 941 942 943 944 945 946

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
947 948
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
964 965
    bundleName: 'com.example.myapplication',
    abilityName: 'EntryAbility',
A
Annie_wang 已提交
966
};
A
Annie_wang 已提交
967 968 969 970 971 972 973 974
let appIds = ['com.example.myapplication'];

bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed uninstall bundles');
A
Annie_wang 已提交
975 976 977 978 979 980 981
});
```

## bundleManager.addDisallowedUninstallBundles

addDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;

A
Annie_wang 已提交
982
Adds the applications that cannot be uninstalled by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
A
Annie_wang 已提交
983 984 985 986 987 988 989 990 991 992 993 994

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
995 996
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be uninstalled by the specified user.<br> - If **userId** is not passed in, the applications cannot be uninstalled by the current user.|
A
Annie_wang 已提交
997 998 999 1000 1001

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
1002
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
A
Annie_wang 已提交
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1017 1018
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
1019
};
A
Annie_wang 已提交
1020
let appIds = ['com.example.myapplication'];
A
Annie_wang 已提交
1021 1022

bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
A
Annie_wang 已提交
1023 1024 1025
  console.info('Succeeded in adding disallowed uninstall bundles');
}).catch((err) => {
  console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
1026 1027 1028 1029 1030 1031 1032
});
```

## bundleManager.removeDisallowedUninstallBundles

removeDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1033
Removes the applications that cannot be uninstalled by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1046
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
A
Annie_wang 已提交
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1062 1063
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
1064
};
A
Annie_wang 已提交
1065 1066 1067 1068 1069 1070 1071 1072
let appIds = ['com.example.myapplication'];

bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed uninstall bundles');
A
Annie_wang 已提交
1073 1074 1075 1076 1077 1078 1079
});
```

## bundleManager.removeDisallowedUninstallBundles

removeDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1080
Removes the applications that cannot be uninstalled by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1093 1094
| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
| callback | AsyncCallback&lt;void&gt;            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1110 1111
    bundleName: 'com.example.myapplication',
    abilityName: 'EntryAbility',
A
Annie_wang 已提交
1112
};
A
Annie_wang 已提交
1113 1114 1115 1116 1117 1118 1119 1120
let appIds = ['com.example.myapplication'];

bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed uninstall bundles');
A
Annie_wang 已提交
1121 1122 1123 1124 1125 1126 1127
});
```

## bundleManager.removeDisallowedUninstallBundles

removeDisallowedUninstallBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;

A
Annie_wang 已提交
1128
Removes the applications that cannot be uninstalled by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
A
Annie_wang 已提交
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1141 1142
| appIds    | Array\&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be uninstalled by the specified user.<br> - If **userId** is not passed in, the applications cannot be uninstalled by the current user.|
A
Annie_wang 已提交
1143 1144 1145 1146 1147

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
A
Annie_wang 已提交
1148
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
A
Annie_wang 已提交
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1163 1164
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
1165
};
A
Annie_wang 已提交
1166
let appIds = ['com.example.myapplication'];
A
Annie_wang 已提交
1167 1168

bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
A
Annie_wang 已提交
1169 1170 1171
  console.info('Succeeded in removing disallowed uninstall bundles');
}).catch((err) => {
  console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
A
Annie_wang 已提交
1172 1173 1174 1175 1176 1177 1178
});
```

## bundleManager.getDisallowedUninstallBundles

getDisallowedUninstallBundles(admin: Want, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

A
Annie_wang 已提交
1179
Obtains the applications that cannot be uninstalled by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1207 1208
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
1209 1210
};

A
Annie_wang 已提交
1211 1212 1213 1214 1215 1216
bundleManager.getDisallowedUninstallBundles(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
A
Annie_wang 已提交
1217 1218 1219 1220 1221 1222 1223
});
```

## bundleManager.getDisallowedUninstallBundles

getDisallowedUninstallBundles(admin: Want, userId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

A
Annie_wang 已提交
1224
Obtains the applications that cannot be uninstalled by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1237
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1253 1254
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
1255 1256
};

A
Annie_wang 已提交
1257 1258 1259 1260 1261 1262
bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
A
Annie_wang 已提交
1263 1264 1265 1266 1267 1268 1269
});
```

## bundleManager.getDisallowedUninstallBundles

getDisallowedUninstallBundles(admin: Want, userId?: number): Promise&lt;Array&lt;string&gt;&gt;

A
Annie_wang 已提交
1270
Obtains the applications that cannot be uninstalled by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
A
Annie_wang 已提交
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282

**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
A
Annie_wang 已提交
1283
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be uninstalled by the specified user.<br> - If **userId** is not passed in, the applications cannot be uninstalled by the current user.|
A
Annie_wang 已提交
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the bundle list obtained.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
A
Annie_wang 已提交
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedUninstallBundles(wantTemp, 100).then((result) => {
  console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
}).catch((err) => {
  console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});
```

## bundleManager.uninstall

uninstall(admin: Want, bundleName: string, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1319
Uninstalls an application of the current user without retaining the bundle data through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1332
| bundleName     | string                             | Yes   | Name of the bundle to uninstall.|
A
Annie_wang 已提交
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
| callback | AsyncCallback&lt;void&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
  }
  console.info('Succeeded in uninstalling bundles');
});
```

## bundleManager.uninstall

uninstall(admin: Want, bundleName: string, userId: number, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1364
Uninstalls an application of the specified user without retaining the bundle data through the specified device administrator application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1377 1378
| bundleName     | string                             | Yes   | Name of the bundle to uninstall.|
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
| callback | AsyncCallback&lt;void&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', 100, (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
  }
  console.info('Succeeded in uninstalling bundles');
});
```

## bundleManager.uninstall

uninstall(admin: Want, bundleName: string, isKeepData: boolean, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1410
Uninstalls an application of the current user through the specified device administrator application. The **isKeepData** parameter specifies whether to retain the bundle data. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1423
| bundleName     | string                             | Yes   | Name of the bundle to uninstall.|
A
Annie_wang 已提交
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
| isKeepData     | boolean                             | Yes   | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
A
Annie_wang 已提交
1442
};
A
Annie_wang 已提交
1443 1444 1445 1446 1447 1448

bundleManager.uninstall(wantTemp, 'bundleName', true, (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
  }
  console.info('Succeeded in uninstalling bundles');
A
Annie_wang 已提交
1449
});
A
Annie_wang 已提交
1450 1451 1452 1453 1454 1455
```

## bundleManager.uninstall

uninstall(admin: Want, bundleName: string, userId: number, isKeepData: boolean, callback: AsyncCallback&lt;void&gt;): void

A
Annie_wang 已提交
1456
Uninstalls an application of the specified user through the specified device administrator application. The **isKeepData** parameter specifies whether to retain the bundle data. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1457 1458 1459 1460 1461 1462 1463 1464

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**
A
Annie_wang 已提交
1465

A
Annie_wang 已提交
1466 1467 1468
| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
A
Annie_wang 已提交
1469 1470
| bundleName     | string                             | Yes   | Name of the bundle to uninstall.|
| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
A
Annie_wang 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
| isKeepData     | boolean                             | Yes   | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', 100, true, (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
  }
  console.info('Succeeded in uninstalling bundles');
});
```

## bundleManager.uninstall

uninstall(admin: Want, bundleName: string, userId?: number, isKeepData?: boolean): Promise&lt;void&gt;

A
Annie_wang 已提交
1503
Uninstalls an application of the current or specified user through the specified device administrator application. The **isKeepData** parameter specifies whether to retain the bundle data. This API uses a promise to return the result.
A
Annie_wang 已提交
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
A
Annie_wang 已提交
1516 1517
| bundleName     | string                             | Yes   | Name of the bundle to uninstall.|
| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the application of the specified user is uninstalled.<br> - If **userId** is not passed in, the application of the current user is uninstalled.|
A
Annie_wang 已提交
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
| isKeepData     | boolean                             | No   | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite.|

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. An error object will be thrown if the bundle fails to be uninstalled.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', 100, true).then(() => {
  console.info('Succeeded in uninstalling bundles');
}).catch((err) => {
  console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});
A
Annie_wang 已提交
1548
```
A
Annie_wang 已提交
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713

## bundleManager.install

install(admin: Want, hapFilePaths: Array\<string>, callback: AsyncCallback\<void>): void

Installs applications through the specified device administrator application. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
| hapFilePaths     | Array\<string>                           | Yes   | Applications to install.|
| callback | AsyncCallback&lt;void&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                |
| 9201002 | the application install failed.                                |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let hapFilePaths = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']

bundleManager.install(wantTemp, hapFilePaths, (err) => {
  if (err) {
    console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`);
  }
  console.info('Succeeded in installing bundles');
});
```

## bundleManager.install

install(admin: Want, hapFilePaths: Array\<string>, installParam: InstallParam, callback: AsyncCallback\<void>): void

Installs applications with specified parameters through the specified device administrator application. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                      |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
| hapFilePaths     | Array\<string>                       | Yes   | Applications to install.|
| installParam     | [InstallParam](#installparam)        | Yes   | Application installation parameters.|
| callback | AsyncCallback&lt;void&gt;       | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                      |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                |
| 9201002 | the application install failed.                                |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let hapFilePaths = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']
let installParam = {
  userId: 100,
  installFlag: 1,
};

bundleManager.install(wantTemp, hapFilePaths, installParam, (err) => {
  if (err) {
    console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`);
  }
  console.info('Succeeded in installing bundles');
});
```

## bundleManager.install

install(admin: Want, hapFilePaths: Array\<string>, installParam?: InstallParam): Promise\<void>

Installs applications through the specified device administrator application. This API uses a promise to return the result.

**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

**System capability**: SystemCapability.Customization.EnterpriseDeviceManager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory  | Description     |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
| hapFilePaths     | Array\<string>                       | Yes   | Applications to install.|
| installParam     | [InstallParam](#installparam)        | No   | Application installation parameters.|

**Return value**

| Type                  | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown.|

**Error codes**

For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).

| ID| Error Message                                                                    |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device.                              |
| 9200002 | the administrator application does not have permission to manage the device.                                          |
| 9201002 | the application install failed.                                |

**Example**

```js
let wantTemp = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let hapFilePaths = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']

bundleManager.install(wantTemp, hapFilePaths).then(() => {
  console.info('Succeeded in installing bundles');
}).catch((err) => {
  console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`);
});
```

## InstallParam

Defines the parameters specified for installing applications.

 **System capability**: SystemCapability.Customization.EnterpriseDeviceManager

 **System API**: This is a system API.

| Name                       | Type                          | Mandatory                        | Description              |
| ------------------------------ | ------------------------------ | ------------------ | ------------------ |
| userId                         | number                         | No                       | User ID, which must be greater than or equal to 0. The default value is the user ID of the caller. |
| installFlag                    | number                         | No                       | Installation flag.<br>- **0**: initial installation.<br>- **1**: overwrite installation.<br>- **2**: installation-free.<br>Default value: **0** |