@ohos.enterprise.bundleManager(包管理)(系统接口)

本模块提供包管理能力,包括添加包安装白名单、获取包安装白名单、移除包安装白名单等。

说明:

本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

本模块接口仅可在Stage模型下使用。

本模块接口仅对设备管理应用开放,需将设备管理应用激活后调用,实现相应功能。

本模块接口均为系统接口。

导入模块

import bundleManager from '@ohos.enterprise.bundleManager';

bundleManager.addAllowedInstallBundles

addAllowedInstallBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用添加应用至包安装白名单,添加至白名单的应用允许在当前用户下安装,否则不允许安装,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.addAllowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding allowed install bundles');
});

bundleManager.addAllowedInstallBundles

addAllowedInstallBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用添加应用至包安装白名单,添加至白名单的应用允许在指定用户(通过userId指定)下安装,否则不允许安装,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding allowed install bundles');
});

bundleManager.addAllowedInstallBundles

addAllowedInstallBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>

指定设备管理应用添加应用至包安装白名单,添加至白名单的应用允许在当前/指定用户下安装,否则不允许安装。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当指定设备管理应用添加包安装白名单失败时,会抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

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'];

bundleManager.addAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
  console.info('Succeeded in adding allowed install bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.removeAllowedInstallBundles

removeAllowedInstallBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用在包安装白名单中移除应用,在白名单存在的情况下,不在包安装白名单中的应用不允许在当前用户下安装,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.removeAllowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing allowed install bundles');
});

bundleManager.removeAllowedInstallBundles

removeAllowedInstallBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用在包安装白名单中移除应用,在白名单存在的情况下,不在包安装白名单中的应用不允许在指定用户(通过userId指定)下安装,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing allowed install bundles');
});

bundleManager.removeAllowedInstallBundles

removeAllowedInstallBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>

指定设备管理应用在包安装白名单中移除应用,在白名单存在的情况下,不在包安装白名单中的应用不允许在当前/指定用户下安装。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array&lt;string> 应用ID数组。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当指定设备管理应用移除包安装白名单失败时,会抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

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'];

bundleManager.removeAllowedInstallBundles(wantTemp, appIds, 100).then(() => {
  console.info('Succeeded in removing allowed install bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.getAllowedInstallBundles

getAllowedInstallBundles(admin: Want, callback: AsyncCallback<Array<string>>): void

指定设备管理应用获取当前用户下的包安装白名单,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
callback AsyncCallback<Array<string>> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getAllowedInstallBundles(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
});

bundleManager.getAllowedInstallBundles

getAllowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void

指定设备管理应用获取指定用户(通过userId指定)下的包安装白名单,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<Array<string>> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getAllowedInstallBundles(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
});

bundleManager.getAllowedInstallBundles

getAllowedInstallBundles(admin: Want, userId?: number): Promise<Array<string>>

指定设备管理应用获取当前/指定用户下的包安装白名单,使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<Array<string>> Promise对象,返回当前用户下的包安装白名单。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getAllowedInstallBundles(wantTemp, 100).then((result) => {
  console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.addDisallowedInstallBundles

addDisallowedInstallBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用添加应用至包安装黑名单,添加至黑名单的应用不允许在当前用户下安装,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.addDisallowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed install bundles');
});

bundleManager.addDisallowedInstallBundles

addDisallowedInstallBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用添加应用至包安装黑名单,添加至黑名单的应用不允许在指定用户(通过userId指定)下安装。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed install bundles');
});

bundleManager.addDisallowedInstallBundles

addDisallowedInstallBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>

指定设备管理应用添加应用至包安装黑名单,添加至黑名单的应用不允许在当前/指定用户下安装。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当指定设备管理应用添加包安装黑名单失败时,会抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

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'];

bundleManager.addDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
  console.info('Succeeded in adding disallowed install bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.removeDisallowedInstallBundles

removeDisallowedInstallBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用在包安装黑名单中移除应用,在黑名单存在的情况下,在包安装黑名单中的应用不允许在当前用户下安装。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed install bundles');
});

bundleManager.removeDisallowedInstallBundles

removeDisallowedInstallBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用在包安装黑名单中移除应用,在黑名单存在的情况下,在包安装黑名单中的应用不允许在指定用户(通过userId指定)下安装,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed install bundles');
});

bundleManager.removeDisallowedInstallBundles

removeDisallowedInstallBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>

指定设备管理应用在包安装黑名单中移除应用,在黑名单存在的情况下,在包安装黑名单中的应用不允许在当前/指定用户下安装。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array&lt;string> 应用ID数组。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当指定设备管理应用移除包安装黑名单失败时,会抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

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'];

bundleManager.removeDisallowedInstallBundles(wantTemp, appIds, 100).then(() => {
  console.info('Succeeded in removing disallowed install bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.getDisallowedInstallBundles

getDisallowedInstallBundles(admin: Want, callback: AsyncCallback<Array<string>>): void

指定设备管理应用获取当前用户下的包安装黑名单,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
callback AsyncCallback<Array<string>> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedInstallBundles(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
});

bundleManager.getDisallowedInstallBundles

getDisallowedInstallBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void

指定设备管理应用获取指定用户(通过userId指定)下的包安装黑名单,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<Array<string>> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedInstallBundles(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
});

bundleManager.getDisallowedInstallBundles

getDisallowedInstallBundles(admin: Want, userId?: number): Promise<Array<string>>

指定设备管理应用获取当前/指定用户下的包安装黑名单,使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<Array<string>> Promise对象,返回当前用户下的包安装白名单。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedInstallBundles(wantTemp, 100).then((result) => {
  console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.addDisallowedUninstallBundles

addDisallowedUninstallBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用添加应用至包卸载黑名单,添加至黑名单的应用不允许在当前用户下卸载,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed uninstall bundles');
});

bundleManager.addDisallowedUninstallBundles

addDisallowedUninstallBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用添加应用至包卸载黑名单,添加至黑名单的应用不允许在指定用户(通过userId指定)下卸载。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in adding disallowed uninstall bundles');
});

bundleManager.addDisallowedUninstallBundles

addDisallowedUninstallBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>

指定设备管理应用添加应用至包卸载黑名单,添加至黑名单的应用不允许在当前/指定用户下卸载。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当指定设备管理应用添加包卸载黑名单失败时,会抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

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'];

bundleManager.addDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
  console.info('Succeeded in adding disallowed uninstall bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.removeDisallowedUninstallBundles

removeDisallowedUninstallBundles(admin: Want, appIds: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用在包卸载黑名单中移除应用,在黑名单存在的情况下,在包卸载黑名单中的应用不允许在当前用户下卸载,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed uninstall bundles');
});

bundleManager.removeDisallowedUninstallBundles

removeDisallowedUninstallBundles(admin: Want, appIds: Array<string>, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用在包卸载黑名单中移除应用,在黑名单存在的情况下,在包卸载黑名单中的应用不允许在指定用户(通过userId指定)下卸载。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array<string> 应用ID数组。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数。当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let appIds: Array<string> = ['com.example.myapplication'];

bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100, (err) => {
  if (err) {
    console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in removing disallowed uninstall bundles');
});

bundleManager.removeDisallowedUninstallBundles

removeDisallowedUninstallBundles(admin: Want, appIds: Array<string>, userId?: number): Promise<void>

指定设备管理应用在包卸载黑名单中移除应用。在黑名单存在的情况下,在包卸载黑名单中的应用不允许在当前/指定用户下卸载。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
appIds Array&lt;string> 应用ID数组。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当指定设备管理应用移除包卸载黑名单失败时会抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

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'];

bundleManager.removeDisallowedUninstallBundles(wantTemp, appIds, 100).then(() => {
  console.info('Succeeded in removing disallowed uninstall bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.getDisallowedUninstallBundles

getDisallowedUninstallBundles(admin: Want, callback: AsyncCallback<Array<string>>): void

指定设备管理应用获取当前用户下的包卸载黑名单,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
callback AsyncCallback<Array<string>> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedUninstallBundles(wantTemp, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
});

bundleManager.getDisallowedUninstallBundles

getDisallowedUninstallBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void

指定设备管理应用获取指定用户(通过userId指定)下的包卸载黑名单,使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<Array<string>> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedUninstallBundles(wantTemp, 100, (err, result) => {
  if (err) {
    console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
});

bundleManager.getDisallowedUninstallBundles

getDisallowedUninstallBundles(admin: Want, userId?: number): Promise<Array<string>>

指定设备管理应用获取当前/指定用户下包卸载黑名单接口,使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。

返回值:

类型 说明
Promise<Array<string>> Promise对象,返回当前用户下的包卸载白名单。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.getDisallowedUninstallBundles(wantTemp, 100).then((result) => {
  console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`);
}).catch((err: BusinessError) => {
  console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.uninstall

uninstall(admin: Want, bundleName: string, callback: AsyncCallback<void>): void

指定设备管理应用卸载当前用户下的指定包,且不保留包数据。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
bundleName string 包名。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in uninstalling bundles');
});

bundleManager.uninstall

uninstall(admin: Want, bundleName: string, userId: number, callback: AsyncCallback<void>): void

指定设备管理应用卸载指定用户下(由参数userId指定)的指定包,且不保留包数据。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
bundleName string 包名。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', 100, (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in uninstalling bundles');
});

bundleManager.uninstall

uninstall(admin: Want, bundleName: string, isKeepData: boolean, callback: AsyncCallback<void>): void

指定设备管理应用卸载当前用户下的指定包,选择是否保留包数据(由isKeepData指定)。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
bundleName string 包名。
isKeepData boolean 是否保留包数据,true表示保留,false表示不保留。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', true, (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in uninstalling bundles');
});

bundleManager.uninstall

uninstall(admin: Want, bundleName: string, userId: number, isKeepData: boolean, callback: AsyncCallback<void>): void

指定设备管理应用卸载指定用户下(由参数userId指定)的指定包接口,选择是否保留包数据(由isKeepData指定)。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
bundleName string 包名。
userId number 用户ID,指定具体用户。取值范围:大于等于0。
isKeepData boolean 是否保留包数据,true表示保留,false表示不保留。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', 100, true, (err) => {
  if (err) {
    console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in uninstalling bundles');
});

bundleManager.uninstall

uninstall(admin: Want, bundleName: string, userId?: number, isKeepData?: boolean): Promise<void>

指定设备管理应用卸载当前/指定用户下的指定包接口,选择是否保留包数据(由isKeepData指定)。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
bundleName string 包名。
userId number 用户ID,取值范围:大于等于0。
- 调用接口时,若传入userId,表示指定用户。
- 调用接口时,若未传入userId,表示当前用户。
isKeepData boolean 是否保留包数据,true表示保留,false表示不保留。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当包卸载失败时抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.

示例:

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};

bundleManager.uninstall(wantTemp, 'bundleName', 100, true).then(() => {
  console.info('Succeeded in uninstalling bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`);
});

bundleManager.install

install(admin: Want, hapFilePaths: Array<string>, callback: AsyncCallback<void>): void

指定设备管理应用安装指定路径下的应用包。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
hapFilePaths Array<string> 待安装应用包路径数组。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.
9201002 the application install failed.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap'];

bundleManager.install(wantTemp, hapFilePaths, (err) => {
  if (err) {
    console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in installing bundles');
});

bundleManager.install

install(admin: Want, hapFilePaths: Array<string>, installParam: InstallParam, callback: AsyncCallback<void>): void

指定设备管理应用安装指定路径下的指定安装参数的应用包,。使用callback异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
hapFilePaths Array<string> 待安装应用包路径数组。
installParam InstallParam 应用包安装参数。
callback AsyncCallback<void> 回调函数,当接口调用成功,err为null,否则为错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.
9201002 the application install failed.

示例:

import Want from '@ohos.app.ability.Want';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap'];
let installParam: bundleManager.InstallParam = {
  userId: 100,
  installFlag: 1,
};

bundleManager.install(wantTemp, hapFilePaths, installParam, (err) => {
  if (err) {
    console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`);
    return;
  }
  console.info('Succeeded in installing bundles');
});

bundleManager.install

install(admin: Want, hapFilePaths: Array<string>, installParam?: InstallParam): Promise<void>

指定设备管理应用安装指定路径下的应用包。使用promise异步回调。

需要权限: ohos.permission.ENTERPRISE_INSTALL_BUNDLE

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

参数:

参数名 类型 必填 说明
admin Want 设备管理应用。
hapFilePaths Array<string> 待安装应用包路径数组。
installParam InstallParam 应用包安装参数。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。当包安装失败时,抛出错误对象。

错误码

以下错误码的详细介绍请参见企业设备管理错误码

错误码ID 错误信息
9200001 the application is not an administrator of the device.
9200002 the administrator application does not have permission to manage the device.
9201002 the application install failed.

示例:

import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let wantTemp: Want = {
  bundleName: 'com.example.myapplication',
  abilityName: 'EntryAbility',
};
let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap'];

bundleManager.install(wantTemp, hapFilePaths).then(() => {
  console.info('Succeeded in installing bundles');
}).catch((err: BusinessError) => {
  console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`);
});

InstallParam

应用包安装需指定的参数信息。

系统能力: SystemCapability.Customization.EnterpriseDeviceManager

系统接口: 此接口为系统接口。

名称 类型 必填 说明
userId number 指示用户id,默认值:调用方所在用户,取值范围:大于等于0。
installFlag number 安装标志。枚举值:0:应用初次安装,1:应用覆盖安装,2:应用免安装,默认值为应用初次安装。