@ohos.enterprise.applicationManager (Application Management (System API)
The applicationManager module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run.
NOTE
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.
The APIs of this module can be used only in the stage model.
The APIs provided by this module can be called only by a device administrator application that is enabled.
The APIs provided by this module are system APIs.
Modules to Import
import applicationManager from '@ohos.enterprise.applicationManager';
applicationManager.addDisallowedRunningBundles
addDisallowedRunningBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void
Adds 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
appIds | Array<string> | Yes | IDs of the applications to add. |
callback | AsyncCallback<void> | 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.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (err) => {
if (err) {
console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in adding disallowed running bundles');
});
applicationManager.addDisallowedRunningBundles
addDisallowedRunningBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void
Adds 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
appIds | Array<string> | Yes | IDs of the applications to add. |
userId | number | Yes | User ID, which must be greater than or equal to 0. |
callback | AsyncCallback<void> | 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.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
if (err) {
console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in adding disallowed running bundles');
});
applicationManager.addDisallowedRunningBundles
addDisallowedRunningBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>
Adds 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
appIds | Array<string> | Yes | IDs of the applications to add. |
userId | number | No | User ID, which must be greater than or equal to 0. - If userId is passed in, the applications cannot be run by the specified user. - If userId is not passed in, the applications cannot be run by the current user. |
Return value
Type | Description |
---|---|
Promise<void> | 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.
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
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];
applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.info('Succeeded in adding disallowed running bundles');
}).catch((err: BusinessError) => {
console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
});
applicationManager.removeDisallowedRunningBundles
removeDisallowedRunningBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void
Removes 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
appIds | Array<string> | Yes | IDs of the applications to remove. |
callback | AsyncCallback<void> | 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.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (err) => {
if (err) {
console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in removing disallowed running bundles');
});
applicationManager.removeDisallowedRunningBundles
removeDisallowedRunningBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void
Removes 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
appIds | Array<string> | Yes | IDs of the applications to remove. |
userId | number | Yes | User ID, which must be greater than or equal to 0. |
callback | AsyncCallback<void> | 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.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (err) => {
if (err) {
console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info('Succeeded in removing disallowed running bundles');
});
applicationManager.removeDisallowedRunningBundles
removeDisallowedRunningBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>
Removes 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
appIds | Array<string> | Yes | IDs of the applications to remove. |
userId | number | No | User ID, which must be greater than or equal to 0. - If userId is passed in, the applications cannot be run by the specified user. - If userId is not passed in, the applications cannot be run by the current user. |
Return value
Type | Description |
---|---|
Promise<void> | 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.
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
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];
applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => {
console.info('Succeeded in removing disallowed running bundles');
}).catch((err: BusinessError) => {
console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
});
applicationManager.getDisallowedRunningBundles
getDisallowedRunningBundles(admin: Want, callback: AsyncCallback<Array<string>>): void
Obtains 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
callback | AsyncCallback<Array<string>> | 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.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
applicationManager.getDisallowedRunningBundles(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
});
applicationManager.getDisallowedRunningBundles
getDisallowedRunningBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void
Obtains 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
userId | number | Yes | User ID, which must be greater than or equal to 0. |
callback | AsyncCallback<Array<string>> | 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.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
applicationManager.getDisallowedRunningBundles(wantTemp, 100, (err, result) => {
if (err) {
console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
});
applicationManager.getDisallowedRunningBundles
getDisallowedRunningBundles(admin: Want, userId?: number): Promise<Array<string>>
Obtains 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.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
userId | number | No | User ID, which must be greater than or equal to 0. - If userId is passed in, the applications cannot be run by the specified user. - If userId is not passed in, the applications cannot be run by the current user. |
Return value
Type | Description |
---|---|
Promise<Array<string>> | Promise used to return the application blocklist of the current user. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes.
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
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
applicationManager.getDisallowedRunningBundles(wantTemp, 100).then((result) => {
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
});
applicationManager.addAutoStartApps11+
addAutoStartApps(admin: Want, autoStartApps: Array<Want>): void
Adds the auto-start applications (applications that automatically run at system startup) through the specified device administrator application. This API returns the result synchronously.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
autoStartApps | Array<Want> | Yes | Auto-start applications to add. A maximum of 10 applications can be added at a time. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let autoStartApps: Array<Want> = [
{
bundleName: 'com.example.autoStartApplication',
abilityName: 'EntryAbility',
}
];
try {
applicationManager.addAutoStartApps(wantTemp, autoStartApps);
console.info(`Succeeded in adding auto start applications`);
} catch(err) {
console.error(`Failed to add auto start applications. Code: ${err.code}, message: ${err.message}`);
}
applicationManager.removeAutoStartApps11+
removeAutoStartApps(admin: Want, autoStartApps: Array<Want>): void
Remotes the auto-start applications through the specified device administrator application. This API returns the result synchronously.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
autoStartApps | Array<Want> | Yes | Auto-start applications to remove. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let autoStartApps: Array<Want> = [
{
bundleName: 'com.example.autoStartApplication',
abilityName: 'EntryAbility',
}
];
try {
applicationManager.removeAutoStartApps(wantTemp, autoStartApps);
console.info(`Succeeded in removing auto start applications`);
} catch(err) {
console.error(`Failed to remove auto start applications. Code: ${err.code}, message: ${err.message}`);
}
applicationManager.getAutoStartApps11+
getAutoStartApps(admin: Want): Array<Want>
Obtains the auto-start applications through the specified device administrator application. This API returns the result synchronously.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | Device administrator application. |
Return value
Type | Description |
---|---|
Array<Want> | List of the auto-start applications obtained. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes.
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
import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let res: Array<Want> = applicationManager.getAutoStartApps(wantTemp);
console.info(`Succeeded in adding auto start apps: ${res}`);
} catch(err) {
console.error(`Failed to auto start apps. Code: ${err.code}, message: ${err.message}`);
}