• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.applicationManager (Application Management)
2
3The **applicationManager** module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run.
4
5> **NOTE**
6>
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.
8>
9> - The APIs of this module can be used only in the stage model.
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).
12
13## Modules to Import
14
15```ts
16import applicationManager from '@ohos.enterprise.applicationManager';
17```
18
19## applicationManager.addDisallowedRunningBundles
20
21addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;
22
23Adds the applications that are not allowed to run by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
24
25**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
26
27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
28
29**System API**: This is a system API.
30
31**Parameters**
32
33| Name     | Type                                      | Mandatory  | Description                      |
34| -------- | ---------------------------------------- | ---- | ------------------------------- |
35| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
36| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
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.|
38
39**Error codes**
40
41For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
42
43| ID| Error Message                                                                      |
44| ------- | ---------------------------------------------------------------------------- |
45| 9200001 | the application is not an administrator of the device.                        |
46| 9200002 | the administrator application does not have permission to manage the device. |
47
48
49**Example**
50
51```ts
52import Want from '@ohos.app.ability.Want';
53let wantTemp: Want = {
54  bundleName: 'com.example.myapplication',
55  abilityName: 'EntryAbility',
56};
57let appIds: Array<string> = ['com.example.myapplication'];
58
59applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (err) => {
60  if (err) {
61    console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
62    return;
63  }
64  console.info('Succeeded in adding disallowed running bundles');
65});
66```
67
68## applicationManager.addDisallowedRunningBundles
69
70addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;
71
72Adds the applications that are not allowed to run by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
73
74**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
75
76**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
77
78**System API**: This is a system API.
79
80**Parameters**
81
82| Name  | Type                                 | Mandatory  | Description     |
83| ----- | ----------------------------------- | ---- | ------- |
84| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
85| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
86| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
87| 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.|
88
89**Error codes**
90
91For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
92
93| ID| Error Message                                                                    |
94| ------- | ---------------------------------------------------------------------------- |
95| 9200001 | the application is not an administrator of the device.                        |
96| 9200002 | the administrator application does not have permission to manage the device. |
97
98**Example**
99
100```ts
101import Want from '@ohos.app.ability.Want';
102let wantTemp: Want = {
103  bundleName: 'com.example.myapplication',
104  abilityName: 'EntryAbility',
105};
106let appIds: Array<string> = ['com.example.myapplication'];
107
108applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
109  if (err) {
110    console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
111    return;
112  }
113  console.info('Succeeded in adding disallowed running bundles');
114});
115```
116
117## applicationManager.addDisallowedRunningBundles
118
119addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;
120
121Adds the applications that are not allowed to run by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
122
123**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
124
125**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
126
127**System API**: This is a system API.
128
129**Parameters**
130
131| Name  | Type                                 | Mandatory  | Description     |
132| ----- | ----------------------------------- | ---- | ------- |
133| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
134| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to add.                 |
135| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be run by the specified user.<br> - If **userId** is not passed in, the applications cannot be run by the current user.|
136
137**Return value**
138
139| Type                  | Description                     |
140| --------------------- | ------------------------- |
141| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
142
143**Error codes**
144
145For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
146
147| ID| Error Message                                                                    |
148| ------- | ---------------------------------------------------------------------------- |
149| 9200001 | the application is not an administrator of the device.                        |
150| 9200002 | the administrator application does not have permission to manage the device. |
151
152**Example**
153
154```ts
155import Want from '@ohos.app.ability.Want';
156import { BusinessError } from '@ohos.base';
157let wantTemp: Want = {
158  bundleName: 'com.example.myapplication',
159  abilityName: 'EntryAbility',
160};
161let appIds: Array<string> = ['com.example.myapplication'];
162
163applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
164  console.info('Succeeded in adding disallowed running bundles');
165}).catch((err: BusinessError) => {
166  console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
167});
168```
169
170## applicationManager.removeDisallowedRunningBundles
171
172removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback&lt;void&gt;): void;
173
174Removes the applications that are not allowed to run by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
175
176**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
177
178**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
179
180**System API**: This is a system API.
181
182**Parameters**
183
184| Name     | Type                                      | Mandatory  | Description                      |
185| -------- | ---------------------------------------- | ---- | ------------------------------- |
186| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
187| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
188| 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.|
189
190**Error codes**
191
192For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
193
194| ID| Error Message                                                                      |
195| ------- | ---------------------------------------------------------------------------- |
196| 9200001 | the application is not an administrator of the device.                        |
197| 9200002 | the administrator application does not have permission to manage the device. |
198
199**Example**
200
201```ts
202import Want from '@ohos.app.ability.Want';
203let wantTemp: Want = {
204  bundleName: 'com.example.myapplication',
205  abilityName: 'EntryAbility',
206};
207let appIds: Array<string> = ['com.example.myapplication'];
208
209applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (err) => {
210  if (err) {
211    console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
212    return;
213  }
214  console.info('Succeeded in removing disallowed running bundles');
215});
216```
217
218## applicationManager.removeDisallowedRunningBundles
219
220removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback&lt;void&gt;): void;
221
222Removes the applications that are not allowed to run by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
223
224**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
225
226**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
227
228**System API**: This is a system API.
229
230**Parameters**
231
232| Name  | Type                                 | Mandatory  | Description     |
233| ----- | ----------------------------------- | ---- | ------- |
234| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
235| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
236| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
237| 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.|
238
239**Error codes**
240
241For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
242
243| ID| Error Message                                                                    |
244| ------- | ---------------------------------------------------------------------------- |
245| 9200001 | the application is not an administrator of the device.                        |
246| 9200002 | the administrator application does not have permission to manage the device. |
247
248**Example**
249
250```ts
251import Want from '@ohos.app.ability.Want';
252let wantTemp: Want = {
253  bundleName: 'com.example.myapplication',
254  abilityName: 'EntryAbility',
255};
256let appIds: Array<string> = ['com.example.myapplication'];
257
258applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
259  if (err) {
260    console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
261    return;
262  }
263  console.info('Succeeded in removing disallowed running bundles');
264});
265```
266
267## applicationManager.removeDisallowedRunningBundles
268
269removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise&lt;void&gt;;
270
271Removes the applications that are not allowed to run by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
272
273**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
274
275**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
276
277**System API**: This is a system API.
278
279**Parameters**
280
281| Name  | Type                                 | Mandatory  | Description     |
282| ----- | ----------------------------------- | ---- | ------- |
283| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
284| appIds    | Array&lt;string&gt;                | Yes   | IDs of the applications to remove.                 |
285| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be run by the specified user.<br> - If **userId** is not passed in, the applications cannot be run by the current user.|
286
287**Return value**
288
289| Type                  | Description                     |
290| --------------------- | ------------------------- |
291| Promise&lt;void&gt; | Promise that returns no value. If the operation fails, an error object will be thrown. |
292
293**Error codes**
294
295For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
296
297| ID| Error Message                                                                    |
298| ------- | ---------------------------------------------------------------------------- |
299| 9200001 | the application is not an administrator of the device.                        |
300| 9200002 | the administrator application does not have permission to manage the device. |
301
302**Example**
303
304```ts
305import Want from '@ohos.app.ability.Want';
306import { BusinessError } from '@ohos.base';
307let wantTemp: Want = {
308  bundleName: 'com.example.myapplication',
309  abilityName: 'EntryAbility',
310};
311let appIds: Array<string> = ['com.example.myapplication'];
312
313applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
314  console.info('Succeeded in removing disallowed running bundles');
315}).catch((err: BusinessError) => {
316  console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
317});
318```
319
320## applicationManager.getDisallowedRunningBundles
321
322getDisallowedRunningBundles(admin: Want, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;
323
324Obtains the applications that are not allowed to run by the current user through the specified device administrator application. This API uses an asynchronous callback to return the result.
325
326**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
327
328**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
329
330**System API**: This is a system API.
331
332**Parameters**
333
334| Name     | Type                                      | Mandatory  | Description                      |
335| -------- | ---------------------------------------- | ---- | ------------------------------- |
336| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
337| 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.      |
338
339**Error codes**
340
341For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
342
343| ID| Error Message                                                                      |
344| ------- | ---------------------------------------------------------------------------- |
345| 9200001 | the application is not an administrator of the device.                        |
346| 9200002 | the administrator application does not have permission to manage the device. |
347
348**Example**
349
350```ts
351import Want from '@ohos.app.ability.Want';
352let wantTemp: Want = {
353  bundleName: 'com.example.myapplication',
354  abilityName: 'EntryAbility',
355};
356
357applicationManager.getDisallowedRunningBundles(wantTemp, (err, result) => {
358  if (err) {
359    console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
360    return;
361  }
362  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
363});
364```
365
366## applicationManager.getDisallowedRunningBundles
367
368getDisallowedRunningBundles(admin: Want, userId: number, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void;
369
370Obtains the applications that are not allowed to run by the specified user through the specified device administrator application. This API uses an asynchronous callback to return the result.
371
372**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
373
374**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
375
376**System API**: This is a system API.
377
378**Parameters**
379
380| Name     | Type                                      | Mandatory  | Description                      |
381| -------- | ---------------------------------------- | ---- | ------------------------------- |
382| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
383| userId     | number                             | Yes   | User ID, which must be greater than or equal to 0.|
384| 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.      |
385
386**Error codes**
387
388For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
389
390| ID| Error Message                                                                      |
391| ------- | ---------------------------------------------------------------------------- |
392| 9200001 | the application is not an administrator of the device.                        |
393| 9200002 | the administrator application does not have permission to manage the device. |
394
395**Example**
396
397```ts
398import Want from '@ohos.app.ability.Want';
399let wantTemp: Want = {
400  bundleName: 'com.example.myapplication',
401  abilityName: 'EntryAbility',
402};
403
404applicationManager.getDisallowedRunningBundles(wantTemp, 100, (err, result) => {
405  if (err) {
406    console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
407    return;
408  }
409  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
410});
411```
412
413## applicationManager.getDisallowedRunningBundles
414
415getDisallowedRunningBundles(admin: Want, userId?: number): Promise&lt;Array&lt;string&gt;&gt;;
416
417Obtains the applications that are not allowed to run by the current or specified user through the specified device administrator application. This API uses a promise to return the result.
418
419**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
420
421**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
422
423**System API**: This is a system API.
424
425**Parameters**
426
427| Name  | Type                                 | Mandatory  | Description     |
428| ----- | ----------------------------------- | ---- | ------- |
429| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
430| userId     | number                             | No   | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be run by the specified user.<br> - If **userId** is not passed in, the applications cannot be run by the current user.|
431
432**Return value**
433
434| Type                  | Description                     |
435| --------------------- | ------------------------- |
436| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the application blocklist of the current user.|
437
438**Error codes**
439
440For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
441
442| ID| Error Message                                                                    |
443| ------- | ---------------------------------------------------------------------------- |
444| 9200001 | the application is not an administrator of the device.                        |
445| 9200002 | the administrator application does not have permission to manage the device. |
446
447**Example**
448
449```ts
450import Want from '@ohos.app.ability.Want';
451import { BusinessError } from '@ohos.base';
452let wantTemp: Want = {
453  bundleName: 'com.example.myapplication',
454  abilityName: 'EntryAbility',
455};
456
457applicationManager.getDisallowedRunningBundles(wantTemp, 100).then((result) => {
458  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
459}).catch((err: BusinessError) => {
460  console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
461});
462```
463