harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management)
@ohos.enterprise.applicationManager (Application Management)
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 12. 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 of this module can be called only by a device administrator application that is enabled.
Modules to Import
import { applicationManager } from '@kit.MDMKit';
applicationManager.addDisallowedRunningBundlesSync
addDisallowedRunningBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void
Adds the applications that are not allowed to run by the current or specified user.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
appIds | Array<string> | Yes | IDs of the applications to add. |
accountId | number | No | User ID, which must be greater than or equal to 0. You can call getOsAccountLocalId of @ohos.account.osAccount to obtain the user ID. - If accountId is passed in, this API applies to the specified user. - If accountId is not passed in, this API applies to the current user. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.******_******/******5t5CoBM='];
try {
applicationManager.addDisallowedRunningBundlesSync(wantTemp, appIds);
console.info('Succeeded in adding disallowed running bundles.');
} catch (err) {
console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
}
applicationManager.removeDisallowedRunningBundlesSync
removeDisallowedRunningBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void
Removes the applications that cannot be run by the current or specified user through the specified device administrator application.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
appIds | Array<string> | Yes | IDs of the applications to add. |
accountId | number | No | User ID, which must be greater than or equal to 0. You can call getOsAccountLocalId of @ohos.account.osAccount to obtain the user ID. - If accountId is passed in, this API applies to the specified user. - If accountId is not passed in, this API applies to the current user. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.******_******/******5t5CoBM='];
try {
applicationManager.removeDisallowedRunningBundlesSync(wantTemp, appIds);
console.info('Succeeded in removing disallowed running bundles.');
} catch (err) {
console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
}
applicationManager.getDisallowedRunningBundlesSync
getDisallowedRunningBundlesSync(admin: Want, accountId?: number): Array<string>
Obtains the applications that are not allowed to run by the current user.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
accountId | number | No | User ID, which must be greater than or equal to 0. You can call getOsAccountLocalId of @ohos.account.osAccount to obtain the user ID. - If accountId is passed in, this API applies to the specified user. - If accountId is not passed in, this API applies to the current user. |
Return value
Type | Description |
---|---|
Array<string> | Applications that are not allowed to run by the current user. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let result: Array<string> = applicationManager.getDisallowedRunningBundlesSync(wantTemp)
console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`);
} catch (err) {
console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`);
}
applicationManager.addAutoStartApps
addAutoStartApps(admin: Want, autoStartApps: Array<Want>): void
Adds the auto-start applications. Currently, this capability supports only 2-in-1 devices.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
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 and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
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.removeAutoStartApps
removeAutoStartApps(admin: Want, autoStartApps: Array<Want>): void
Removes the auto-start applications. Currently, this capability supports only 2-in-1 devices.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
autoStartApps | Array<Want> | Yes | Auto-start applications to remove. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
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.getAutoStartApps
getAutoStartApps(admin: Want): Array<Want>
Queries the auto-start applications. Currently, this capability supports only 2-in-1 devices.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
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 and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
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: ${JSON.stringify(res)}`);
} catch(err) {
console.error(`Failed to auto start apps. Code: ${err.code}, message: ${err.message}`);
}
applicationManager.addKeepAliveApps14+
addKeepAliveApps(admin: Want, bundleNames: Array<string>, accountId: number): void
Adds applications to be kept alive. Currently, this feature is available only for 2-in-1 devices. If applications are disallowed to run by calling addDisallowedRunningBundlesSync, they cannot be kept alive. Otherwise, a conflict occurs.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
bundleNames | Array<string> | Yes | Application bundle name array, which specifies the applications to be kept alive. A maximum of five applications are supported. |
accountId | number | Yes | User ID, which must be greater than or equal to 0. You can call getOsAccountLocalId of @ohos.account.osAccount to obtain the user ID. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
9200010 | A conflict policy has been configured. |
9201005 | Add keep alive applications failed. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let bundleNames: Array<string> = ['com.example.myapplication'];
try {
applicationManager.addKeepAliveApps(wantTemp, bundleNames, 100);
console.info('Succeeded in adding keep alive apps.');
} catch (err) {
console.error(`Failed to add keep alive apps. Code is ${err.code}, message is ${err.message}`);
}
applicationManager.removeKeepAliveApps14+
removeKeepAliveApps(admin: Want, bundleNames: Array<string>, accountId: number): void
Removes applications to be kept alive. Currently, this feature is available only for 2-in-1 devices.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
bundleNames | Array<string> | Yes | Application bundle name array, which specifies the applications to be kept alive. A maximum of five applications are supported. |
accountId | number | Yes | User ID, which must be greater than or equal to 0. You can call getOsAccountLocalId of @ohos.account.osAccount to obtain the user ID. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let bundleNames: Array<string> = ['com.example.myapplication'];
try {
applicationManager.removeKeepAliveApps(wantTemp, bundleNames, 100);
console.info('Succeeded in removing keep alive apps.');
} catch (err) {
console.error(`Failed to remove keep alive apps. Code is ${err.code}, message is ${err.message}`);
}
applicationManager.getKeepAliveApps14+
getKeepAliveApps(admin: Want, accountId: number): Array<string>
Application bundle name array, which specifies the applications to be kept alive. A maximum of five applications are supported.
Required permissions: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
System capability: SystemCapability.Customization.EnterpriseDeviceManager
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
admin | Want | Yes | EnterpriseAdminExtensionAbility. |
accountId | number | Yes | User ID, which must be greater than or equal to 0. You can call getOsAccountLocalId of @ohos.account.osAccount to obtain the user ID. |
Return value
Type | Description |
---|---|
Array<string> | Bundle name of the application kept alive for the specified user. |
Error codes
For details about the error codes, see Enterprise Device Management Error Codes and Universal Error Codes.
ID | Error Message |
---|---|
9200001 | The application is not an administrator application of the device. |
9200002 | The administrator application does not have permission to manage the device. |
201 | Permission verification failed. The application does not have the permission required to call the API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
Example
import { Want } from '@kit.AbilityKit';
let wantTemp: Want = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
try {
let result: Array<string> = applicationManager.getKeepAliveApps(wantTemp, 100);
console.info('Succeeded in getting keep alive apps.');
} catch (err) {
console.error(`Failed to get keep alive apps. Code is ${err.code}, message is ${err.message}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Enterprise Device Management Error Codes
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
harmony 鸿蒙@ohos.enterprise.accountManager (Account Management) (System API)
harmony 鸿蒙@ohos.enterprise.accountManager (Account Management)
harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management) (System API)
harmony 鸿蒙@ohos.enterprise.adminManager (Enterprise Device Management)
harmony 鸿蒙@ohos.enterprise.applicationManager (Application Management (System API)
harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management) (System API)
harmony 鸿蒙@ohos.enterprise.bluetoothManager (Bluetooth Management)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦