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 12. 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 of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled.
12>
13
14## Modules to Import
15
16```ts
17import { applicationManager } from '@kit.MDMKit';
18```
19
20## applicationManager.addDisallowedRunningBundlesSync
21
22addDisallowedRunningBundlesSync(admin: Want, appIds: Array\<string>, accountId?: number): void
23
24Adds the applications that are not allowed to run by the current or specified user through the specified device administrator application.
25
26**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
27
28**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
29
30
31
32**Parameters**
33
34| Name   | Type                                                   | Mandatory| Description                                                        |
35| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
36| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
37| appIds    | Array&lt;string&gt;                                     | Yes  | IDs of the applications to add.                                  |
38| accountId | number                                                  | No  | User ID, which must be greater than or equal to 0.<br>- If **accountId** is passed in, this API applies to the specified user.<br>- If **accountId** is not passed in, this API applies to the current user.|
39
40**Error codes**
41
42For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
43
44| ID| Error Message                                                    |
45| -------- | ------------------------------------------------------------ |
46| 9200001  | The application is not an administrator application of the device. |
47| 9200002  | The administrator application does not have permission to manage the device. |
48| 201      | Permission verification failed. The application does not have the permission required to call the API. |
49| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
50
51**Example**
52
53```ts
54import { Want } from '@kit.AbilityKit';
55let wantTemp: Want = {
56  bundleName: 'com.example.myapplication',
57  abilityName: 'EntryAbility',
58};
59let appIds: Array<string> = ['com.example.myapplication'];
60
61try {
62  applicationManager.addDisallowedRunningBundlesSync(wantTemp, appIds);
63  console.info('Succeeded in adding disallowed running bundles.');
64} catch (err) {
65  console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
66}
67```
68
69## applicationManager.removeDisallowedRunningBundlesSync
70
71removeDisallowedRunningBundlesSync(admin: Want, appIds:  Array\<string>, accountId?: number): void
72
73Removes the applications that cannot be run by the current or specified user through the specified device administrator application.
74
75**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
76
77**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
78
79
80
81**Parameters**
82
83| Name   | Type                                                   | Mandatory| Description                                                        |
84| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
85| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
86| appIds    | Array&lt;string&gt;                                     | Yes  | IDs of the applications to remove.                                  |
87| accountId | number                                                  | No  | User ID, which must be greater than or equal to 0.<br>- If **accountId** is passed in, this API applies to the specified user.<br>- If **accountId** is not passed in, this API applies to the current user.|
88
89**Error codes**
90
91For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
92
93| ID| Error Message                                                    |
94| -------- | ------------------------------------------------------------ |
95| 9200001  | The application is not an administrator application of the device. |
96| 9200002  | The administrator application does not have permission to manage the device. |
97| 201      | Permission verification failed. The application does not have the permission required to call the API. |
98| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
99
100**Example**
101
102```ts
103import { Want } from '@kit.AbilityKit';
104let wantTemp: Want = {
105  bundleName: 'com.example.myapplication',
106  abilityName: 'EntryAbility',
107};
108let appIds: Array<string> = ['com.example.myapplication'];
109
110try {
111  applicationManager.removeDisallowedRunningBundlesSync(wantTemp, appIds);
112  console.info('Succeeded in removing disallowed running bundles.');
113} catch (err) {
114  console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
115}
116```
117
118## applicationManager.getDisallowedRunningBundlesSync
119
120getDisallowedRunningBundlesSync(admin: Want, accountId?: number): Array&lt;string>
121
122Obtains the applications that are not allowed to run by the current user through the specified device administrator application.
123
124**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
125
126**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
127
128
129
130**Parameters**
131
132| Name   | Type                                                   | Mandatory| Description                                                        |
133| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
134| admin     | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
135| accountId | number                                                  | No  | User ID, which must be greater than or equal to 0.<br>- If **accountId** is passed in, this API applies to the specified user.<br>- If **accountId** is not passed in, this API applies to the current user.|
136
137**Return value**
138
139| Type               | Description                            |
140| ------------------- | -------------------------------- |
141| Array&lt;string&gt; | Applications that are not allowed to run by the current user.|
142
143**Error codes**
144
145For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
146
147| ID| Error Message                                                    |
148| -------- | ------------------------------------------------------------ |
149| 9200001  | The application is not an administrator application of the device. |
150| 9200002  | The administrator application does not have permission to manage the device. |
151| 201      | Permission verification failed. The application does not have the permission required to call the API. |
152| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
153
154**Example**
155
156```ts
157import { Want } from '@kit.AbilityKit';
158let wantTemp: Want = {
159  bundleName: 'com.example.myapplication',
160  abilityName: 'EntryAbility',
161};
162
163try {
164  let result: Array<string> = applicationManager.getDisallowedRunningBundlesSync(wantTemp)
165  console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
166} catch (err) {
167  console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
168}
169```
170
171## applicationManager.addAutoStartApps
172
173addAutoStartApps(admin: Want, autoStartApps: Array\<Want>): void
174
175Adds the auto-start applications (applications that automatically run at system startup) through the specified device administrator application. This API returns the result synchronously. Currently, this capability supports only 2-in-1 devices.
176
177**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
178
179**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
180
181**Parameters**
182
183| Name       | Type                                                        | Mandatory| Description                                  |
184| ------------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
185| admin         | [Want](../apis-ability-kit/js-apis-app-ability-want.md)      | Yes  | Device administrator application.                        |
186| autoStartApps | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | Yes  | Auto-start applications to add. A maximum of 10 applications can be added at a time.|
187
188**Error codes**
189
190For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
191
192| ID| Error Message                                                    |
193| -------- | ------------------------------------------------------------ |
194| 9200001  | The application is not an administrator application of the device. |
195| 9200002  | The administrator application does not have permission to manage the device. |
196| 201      | Permission verification failed. The application does not have the permission required to call the API. |
197| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
198
199**Example**
200
201```ts
202import { Want } from '@kit.AbilityKit';
203
204let wantTemp: Want = {
205  bundleName: 'com.example.myapplication',
206  abilityName: 'EntryAbility',
207};
208let autoStartApps: Array<Want> = [
209  {
210    bundleName: 'com.example.autoStartApplication',
211    abilityName: 'EntryAbility',
212  }
213];
214
215try {
216  applicationManager.addAutoStartApps(wantTemp, autoStartApps);
217  console.info(`Succeeded in adding auto start applications.`);
218} catch(err) {
219  console.error(`Failed to add auto start applications. Code: ${err.code}, message: ${err.message}`);
220}
221```
222
223## applicationManager.removeAutoStartApps
224
225removeAutoStartApps(admin: Want, autoStartApps: Array\<Want>): void
226
227Removes the auto-start applications through the specified device administrator application. This API returns the result synchronously. Currently, this capability supports only 2-in-1 devices.
228
229**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
230
231**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
232
233**Parameters**
234
235| Name       | Type                                                        | Mandatory| Description            |
236| ------------- | ------------------------------------------------------------ | ---- | ---------------- |
237| admin         | [Want](../apis-ability-kit/js-apis-app-ability-want.md)      | Yes  | Device administrator application.  |
238| autoStartApps | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | Yes  | Auto-start applications to remove.|
239
240**Error codes**
241
242For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
243
244| ID| Error Message                                                    |
245| -------- | ------------------------------------------------------------ |
246| 9200001  | The application is not an administrator application of the device. |
247| 9200002  | The administrator application does not have permission to manage the device. |
248| 201      | Permission verification failed. The application does not have the permission required to call the API. |
249| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
250
251**Example**
252
253```ts
254import { Want } from '@kit.AbilityKit';
255
256let wantTemp: Want = {
257  bundleName: 'com.example.myapplication',
258  abilityName: 'EntryAbility',
259};
260let autoStartApps: Array<Want> = [
261  {
262    bundleName: 'com.example.autoStartApplication',
263    abilityName: 'EntryAbility',
264  }
265];
266
267try {
268  applicationManager.removeAutoStartApps(wantTemp, autoStartApps);
269  console.info(`Succeeded in removing auto start applications.`);
270} catch(err) {
271  console.error(`Failed to remove auto start applications. Code: ${err.code}, message: ${err.message}`);
272}
273```
274
275## applicationManager.getAutoStartApps
276
277getAutoStartApps(admin: Want): Array\<Want>
278
279Obtains the auto-start applications through the specified device administrator application. This API returns the result synchronously. Currently, this capability supports only 2-in-1 devices.
280
281**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
282
283**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
284
285**Parameters**
286
287| Name| Type                                                   | Mandatory| Description          |
288| ------ | ------------------------------------------------------- | ---- | -------------- |
289| admin  | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.|
290
291**Return value**
292
293| Type                                                        | Description                |
294| ------------------------------------------------------------ | -------------------- |
295| Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | List of the auto-start applications obtained.|
296
297**Error codes**
298
299For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
300
301| ID| Error Message                                                    |
302| -------- | ------------------------------------------------------------ |
303| 9200001  | The application is not an administrator application of the device. |
304| 9200002  | The administrator application does not have permission to manage the device. |
305| 201      | Permission verification failed. The application does not have the permission required to call the API. |
306| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
307
308**Example**
309
310```ts
311import { Want } from '@kit.AbilityKit';
312
313let wantTemp: Want = {
314  bundleName: 'com.example.myapplication',
315  abilityName: 'EntryAbility',
316};
317
318try {
319  let res: Array<Want> = applicationManager.getAutoStartApps(wantTemp);
320  console.info(`Succeeded in adding auto start apps: ${JSON.stringify(res)}`);
321} catch(err) {
322  console.error(`Failed to auto start apps. Code: ${err.code}, message: ${err.message}`);
323}
324```
325