harmony 鸿蒙@ohos.enterprise.applicationManager(应用管理)
@ohos.enterprise.applicationManager(应用管理)
本模块提供应用管理能力,包括添加应用运行黑名单、获取应用运行黑名单、移除应用运行黑名单等。
说明:
本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
本模块接口仅可在Stage模型下使用。
本模块接口仅对设备管理应用开放,且调用接口前需激活设备管理应用,具体请参考MDM Kit开发指南。
导入模块
import { applicationManager } from '@kit.MDMKit';
applicationManager.addDisallowedRunningBundlesSync
addDisallowedRunningBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void
添加应用至应用运行黑名单,添加至黑名单的应用不允许在当前/指定用户下运行。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
appIds | Array<string> | 是 | 应用ID数组,指定具体应用。 |
accountId | number | 否 | 用户ID,取值范围:大于等于0。 accountId可以通过@ohos.account.osAccount中的getOsAccountLocalId等接口来获取。 - 调用接口时,若传入accountId,表示指定用户。 - 调用接口时,若未传入accountId,表示当前用户。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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
将应用从当前/指定用户下的应用运行黑名单中移除。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
appIds | Array<string> | 是 | 应用ID数组,指定具体应用。 |
accountId | number | 否 | 用户ID,取值范围:大于等于0。 accountId可以通过@ohos.account.osAccount中的getOsAccountLocalId等接口来获取。 - 调用接口时,若传入accountId,表示指定用户。 - 调用接口时,若未传入accountId,表示当前用户。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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>
获取当前/指定用户下的应用运行黑名单。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
accountId | number | 否 | 用户ID,取值范围:大于等于0。 accountId可以通过@ohos.account.osAccount中的getOsAccountLocalId等接口来获取。 - 调用接口时,若传入accountId,表示指定用户。 - 调用接口时,若未传入accountId,表示当前用户。 |
返回值:
类型 | 说明 |
---|---|
Array<string> | 返回当前/指定用户下的应用运行黑名单。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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
添加开机自启动应用名单。该能力当前仅支持2in1设备。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
autoStartApps | Array<Want> | 是 | 开机自启动应用。数组长度上限为10。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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
删除开机自启动应用名单。该能力当前仅支持2in1设备。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
autoStartApps | Array<Want> | 是 | 开机自启动应用。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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>
查询开机自启动应用名单。该能力当前仅支持2in1设备。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
返回值:
类型 | 说明 |
---|---|
Array<Want> | 应用自启动名单数组。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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
添加保活应用,当前仅支持2in1设备。如果将应用添加至应用运行黑名单addDisallowedRunningBundlesSync,就不能将应用添加至保活,否则会冲突。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
bundleNames | Array<string> | 是 | 应用包名数组,指定需要添加保活的应用,最大支持5个。 |
accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过@ohos.account.osAccount中的getOsAccountLocalId等接口来获取。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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
移除保活应用,当前仅支持2in1设备。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
bundleNames | Array<string> | 是 | 应用包名数组,指定需要移除保活的应用,最大支持5个。 |
accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过@ohos.account.osAccount中的getOsAccountLocalId等接口来获取。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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>
获取保活应用包名,当前仅支持2in1设备。
需要权限: ohos.permission.ENTERPRISE_MANAGE_APPLICATION
系统能力: SystemCapability.Customization.EnterpriseDeviceManager
参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
admin | Want | 是 | 企业设备管理扩展组件。 |
accountId | number | 是 | 用户ID,取值范围:大于等于0。 accountId可以通过@ohos.account.osAccount中的getOsAccountLocalId等接口来获取。 |
返回值:
类型 | 说明 |
---|---|
Array<string> | 返回指定用户下保活应用的包名。 |
错误码:
错误码ID | 错误信息 |
---|---|
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. |
示例:
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 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility(企业设备管理扩展能力)
harmony 鸿蒙@ohos.enterprise.accountManager(账户管理)(系统接口)
harmony 鸿蒙@ohos.enterprise.accountManager(账户管理)
harmony 鸿蒙@ohos.enterprise.adminManager(企业设备管理)(系统接口)
harmony 鸿蒙@ohos.enterprise.adminManager (admin权限管理)
harmony 鸿蒙@ohos.enterprise.applicationManager(应用管理)(系统接口)
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦