# @ohos.bundle.installer (installer模块)(系统接口) > **说明:** > > 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > > 本模块为系统接口。 在设备上安装、升级和卸载应用。 ## 导入模块 ```js import { installer } from '@kit.AbilityKit'; ``` ## BundleInstaller.getBundleInstaller getBundleInstaller(callback: AsyncCallback\): void 获取BundleInstaller对象,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | callback | AsyncCallback\ | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),获取BundleInstaller对象,err为null,data为获取到的BundleInstaller对象;否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; try { installer.getBundleInstaller((err: BusinessError, data: installer.BundleInstaller) => { if (err) { console.error('getBundleInstaller failed:' + err.message); } else { console.info('getBundleInstaller successfully'); } }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed:' + message); } ``` ## BundleInstaller.getBundleInstaller getBundleInstaller(): Promise\ 获取BundleInstaller对象,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | ------------------------------------ | | Promise\ | Promise对象,返回BundleInstaller对象。 | **错误码:** 以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { console.info('getBundleInstaller successfully.'); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.getBundleInstallerSync10+ getBundleInstallerSync(): BundleInstaller 获取并返回BundleInstaller对象。 **系统接口:** 此接口为系统接口。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **返回值:** | 类型 | 说明 | | ------------------------------------------------------------ | ------------------------------------ | | BundleInstaller | 返回BundleInstaller对象。 | **错误码:** 以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 202 | Permission verification failed. A non-system application calls a system API. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; try { installer.getBundleInstallerSync(); console.info('getBundleInstallerSync successfully.'); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstallerSync failed. Cause: ' + message); } ``` ## BundleInstaller.install install(hapFilePaths: Array<string>, installParam: InstallParam, callback: AsyncCallback<void>): void 安装应用,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_BUNDLE10+ 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE10+ 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE10+ > **说明:** 从API version 10起,可通过ohos.permission.INSTALL_ENTERPRISE_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限调用此接口。 > > 安装企业应用需要ohos.permission.INSTALL_ENTERPRISE_BUNDLE权限。 > > 安装企业NORMAL应用需要ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE或ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 > > 安装企业MDM应用需要ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 > > 安装普通应用需要ohos.permission.INSTALL_BUNDLE权限。 > > 安装开发者内测构建应用需要ohos.permission.INSTALL_INTERNALTESTING_BUNDLE权限。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | | installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),安装应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000. | | 17700004 | The specified user ID is not found. | | 17700010 | Failed to install the HAP because the HAP fails to be parsed. | | 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | | 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | | 17700015 | Failed to install the HAPs because they have different configuration information. | | 17700016 | Failed to install the HAP because of insufficient system disk space. | | 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | | 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | | 17700031 | Failed to install the HAP because the overlay check of the HAP failed. | | 17700036 | Failed to install the HSP due to the lack of required permission. | | 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | | 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | | 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | | 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | | 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | | 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | | 17700048 | Failed to install the HAP because the code signature verification failed. | | 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | | 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. | | 17700054 | Failed to install the HAP because the HAP requests wrong permissions.| | 17700058 | Failed to install the HAP because the device has been controlled. | | 17700066 | Failed to install the HAP because installing the native package failed. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | | 17700076 | Failed to install the HAP or HSP because the app distribution type is not allowed. | | 17700077 | Failed to install the HAP and restore to preinstalled bundle. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.install(hapFilePaths, installParam, (err: BusinessError) => { if (err) { console.error('install failed:' + err.message); } else { console.info('install successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.install install(hapFilePaths: Array<string>, callback: AsyncCallback<void>): void 安装应用,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_BUNDLE10+ 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE10+ 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE10+ > **说明:** 从API version 10起,可通过ohos.permission.INSTALL_ENTERPRISE_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限调用此接口。 > > 安装企业应用需要ohos.permission.INSTALL_ENTERPRISE_BUNDLE权限。 > > 安装企业NORMAL应用需要ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE或ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 > > 安装企业MDM应用需要ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 > > 安装普通应用需要ohos.permission.INSTALL_BUNDLE权限。 > > 安装开发者内测构建应用需要ohos.permission.INSTALL_INTERNALTESTING_BUNDLE权限。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),安装应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700010 | Failed to install the HAP because the HAP fails to be parsed. | | 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | | 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | | 17700015 | Failed to install the HAPs because they have different configuration information. | | 17700016 | Failed to install the HAP because of insufficient system disk space. | | 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | | 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | | 17700031 | Failed to install the HAP because the overlay check of the HAP failed. | | 17700036 | Failed to install the HSP due to the lack of required permission. | | 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | | 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | | 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | | 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | | 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | | 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | | 17700048 | Failed to install the HAP because the code signature verification failed. | | 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | | 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. | | 17700054 | Failed to install the HAP because the HAP requests wrong permissions.| | 17700058 | Failed to install the HAP because the device has been controlled. | | 17700066 | Failed to install the HAP because installing the native package failed. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | | 17700076 | Failed to install the HAP or HSP because the app distribution type is not allowed. | | 17700077 | Failed to install the HAP and restore to preinstalled bundle. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.install(hapFilePaths, (err: BusinessError) => { if (err) { console.error('install failed:' + err.message); } else { console.info('install successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.install install(hapFilePaths: Array\, installParam?: InstallParam) : Promise\ 安装应用,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_BUNDLE10+ 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE10+ 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE10+ > **说明:** 从API version 10起,可通过ohos.permission.INSTALL_ENTERPRISE_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限调用此接口。 > > 安装企业应用需要ohos.permission.INSTALL_ENTERPRISE_BUNDLE权限。 > > 安装企业NORMAL应用需要ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE或ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 > > 安装企业MDM应用需要ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 > > 安装普通应用需要ohos.permission.INSTALL_BUNDLE权限。 > > 安装开发者内测构建应用需要ohos.permission.INSTALL_INTERNALTESTING_BUNDLE权限。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | hapFilePaths | Array\ | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | | installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000. | | 17700004 | The specified user ID is not found. | | 17700010 | Failed to install the HAP because the HAP fails to be parsed. | | 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | | 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | | 17700015 | Failed to install the HAPs because they have different configuration information. | | 17700016 | Failed to install the HAP because of insufficient system disk space. | | 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | | 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | | 17700031 | Failed to install the HAP because the overlay check of the HAP failed. | | 17700036 | Failed to install the HSP due to the lack of required permission. | | 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | | 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | | 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | | 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | | 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | | 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | | 17700048 | Failed to install the HAP because the code signature verification failed. | | 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | | 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. | | 17700054 | Failed to install the HAP because the HAP requests wrong permissions.| | 17700058 | Failed to install the HAP because the device has been controlled. | | 17700066 | Failed to install the HAP because installing the native package failed. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | | 17700076 | Failed to install the HAP or HSP because the app distribution type is not allowed. | | 17700077 | Failed to install the HAP and restore to preinstalled bundle. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.install(hapFilePaths, installParam) .then((data: void) => { console.info('install successfully: ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.error('install failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstall uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void 卸载应用,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | | bundleName | string | 是 | 待卸载应用的包名。 | | installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),卸载应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700004 | The specified user ID is not found. | | 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | | 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. | | 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | | 17700060 | The specified application cannot be uninstalled. | | 17700062 | Failed to uninstall the app because the app is locked. | | 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.demo'; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1 }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstall(bundleName, installParam, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstall uninstall(bundleName: string, callback: AsyncCallback<void>): void 卸载应用,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | | bundleName | string | 是 | 待卸载应用的包名。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),卸载应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | | 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. | | 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | | 17700060 | The specified application cannot be uninstalled. | | 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.demo'; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstall(bundleName, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstall uninstall(bundleName: string, installParam?: InstallParam) : Promise\ 卸载应用,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 待卸载应用的包名。 | | installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700004 | The specified user ID is not found. | | 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | | 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. | | 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | | 17700060 | The specified application cannot be uninstalled. | | 17700062 | Failed to uninstall the app because the app is locked. | | 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.demo'; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstall(bundleName, installParam) .then((data: void) => { console.info('uninstall successfully: ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.error('uninstall failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.recover recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void 回滚应用到初次安装时的状态,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | | bundleName | string | 是 | 待恢复应用的包名。 | | installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),回滚应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700004 | The specified user ID is not found. | | 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.demo'; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1 }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.recover(bundleName, installParam, (err: BusinessError) => { if (err) { console.error('recover failed:' + err.message); } else { console.info('recover successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.recover recover(bundleName: string, callback: AsyncCallback<void>): void 回滚应用到初次安装时的状态,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | | bundleName | string | 是 | 待恢复应用的包名。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),回滚应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.demo'; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.recover(bundleName, (err: BusinessError) => { if (err) { console.error('recover failed:' + err.message); } else { console.info('recover successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.recover recover(bundleName: string, installParam?: InstallParam) : Promise\ 回滚应用到初次安装时的状态,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 待卸载应用的包名。 | | installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700004 | The specified user ID is not found. | | 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.demo'; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.recover(bundleName, installParam) .then((data: void) => { console.info('recover successfully: ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.error('recover failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstall10+ uninstall(uninstallParam: UninstallParam, callback : AsyncCallback\) : void 卸载一个共享包,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------------- | ----------------------------------- | ---- | -------------------------------------------------------- | | uninstallParam | [UninstallParam](#uninstallparam10) | 是 | 共享包卸载需指定的参数信息。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),卸载应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | | 17700037 | The version of the shared bundle is dependent on other applications. | | 17700038 | The specified shared bundle does not exist. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let uninstallParam: installer.UninstallParam = { bundleName: "com.ohos.demo", }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstall(uninstallParam, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstall10+ uninstall(uninstallParam: UninstallParam) : Promise\ 卸载一个共享包,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------------- | ----------------------------------- | ---- | ---------------------------- | | uninstallParam | [UninstallParam](#uninstallparam10) | 是 | 共享包卸载需指定的参数信息。 | **返回值:** | 类型 | 说明 | | ------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | | 17700037 | The version of the shared bundle is dependent on other applications. | | 17700038 | The specified shared bundle does not exist. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let uninstallParam: installer.UninstallParam = { bundleName: "com.ohos.demo", }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstall(uninstallParam, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.addExtResource12+ addExtResource(bundleName: string, filePaths: Array\): Promise\; 根据给定的bundleName和hsp文件路径添加扩展资源,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------------- | ----------------------------------- | ---- | ---------------------------- | | bundleName | string | 是 | 要添加扩展资源的应用名称。 | | filePaths | Array\ | 是 | 要添加扩展资源的资源路径。 | **返回值:** | 类型 | 说明 | | ------------- | -------------------------------------- | | Promise\ | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundleName is not found. | | 17700301 | Failed to add extended resources. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import hilog from '@ohos.hilog'; import { BusinessError } from '@ohos.base'; let bundleName : string = 'com.ohos.demo'; let filePaths : Array = ['/data/storage/el2/base/a.hsp']; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.addExtResource(bundleName, filePaths).then((data) => { hilog.info(0x0000, 'testTag', 'addExtResource successfully'); }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', 'addExtResource failed. Cause: %{public}s', err.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.removeExtResource12+ removeExtResource(bundleName: string, moduleNames: Array\): Promise\; 根据给定的bundleName和moduleNames删除扩展资源,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------------- | ----------------------------------- | ---- | ---------------------------- | | bundleName | string | 是 | 要删除扩展资源的应用名称。 | | moduleNames | Array\ | 是 | 要删除扩展资源的moduleNames。 | **返回值:** | 类型 | 说明 | | ------------- | -------------------------------------- | | Promise\ | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundleName is not found. | | 17700302 | Failed to remove extended resources. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import hilog from '@ohos.hilog'; import { BusinessError } from '@ohos.base'; let bundleName : string = 'com.ohos.demo'; let moduleNames : Array = ['moduleTest']; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.removeExtResource(bundleName, moduleNames).then((data) => { hilog.info(0x0000, 'testTag', 'removeExtResource successfully'); }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', 'removeExtResource failed. Cause: %{public}s', err.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.updateBundleForSelf10+ updateBundleForSelf(hapFilePaths: Array\, installParam: InstallParam, callback: AsyncCallback\): void 更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_SELF_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | | installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),安装应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000. | | 17700004 | The specified user ID is not found. | | 17700010 | Failed to install the HAP because the HAP fails to be parsed. | | 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | | 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | | 17700015 | Failed to install the HAPs because they have different configuration information. | | 17700016 | Failed to install the HAP because of insufficient system disk space. | | 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | | 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | | 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | | 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | | 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | | 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | | 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | | 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | | 17700048 | Failed to install the HAP because the code signature verification failed. | | 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | | 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | | 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.updateBundleForSelf(hapFilePaths, installParam, (err: BusinessError) => { if (err) { console.error('updateBundleForSelf failed:' + err.message); } else { console.info('updateBundleForSelf successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.updateBundleForSelf10+ updateBundleForSelf(hapFilePaths: Array\, callback: AsyncCallback\): void 更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用callback异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_SELF_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | | callback | AsyncCallback<void> | 是 | [回调函数](../apis-basic-services-kit/js-apis-base.md#asynccallback),安装应用成功,err为null,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700010 | Failed to install the HAP because the HAP fails to be parsed. | | 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | | 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | | 17700015 | Failed to install the HAPs because they have different configuration information. | | 17700016 | Failed to install the HAP because of insufficient system disk space. | | 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | | 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | | 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | | 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | | 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | | 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | | 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | | 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | | 17700048 | Failed to install the HAP because the code signature verification failed. | | 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | | 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | | 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.updateBundleForSelf(hapFilePaths, (err: BusinessError) => { if (err) { console.error('updateBundleForSelf failed:' + err.message); } else { console.info('updateBundleForSelf successfully.'); } }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.updateBundleForSelf10+ updateBundleForSelf(hapFilePaths: Array\, installParam?: InstallParam): Promise\ 更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_SELF_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | | installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | **返回值:** | 类型 | 说明 | | ------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000. | | 17700004 | The specified user ID is not found. | | 17700010 | Failed to install the HAP because the HAP fails to be parsed. | | 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | | 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | | 17700015 | Failed to install the HAPs because they have different configuration information. | | 17700016 | Failed to install the HAP because of insufficient system disk space. | | 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | | 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | | 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | | 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | | 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | | 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | | 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | | 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | | 17700048 | Failed to install the HAP because the code signature verification failed. | | 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | | 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | | 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.updateBundleForSelf(hapFilePaths, installParam) .then((data: void) => { console.info('updateBundleForSelf successfully: ' + JSON.stringify(data)); }).catch((error: BusinessError) => { console.error('updateBundleForSelf failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstallUpdates12+ uninstallUpdates(bundleName: string, installParam?: InstallParam): Promise\; 对预置应用进行卸载更新,恢复到初次安装时的状态,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 待卸载更新应用的包名。 | | installParam | [InstallParam](#installparam) | 否 | 指定卸载更新所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。其中userId无法指定,调用本接口将对所有已安装相应应用的用户进行卸载更新操作。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundle name is not found. | | 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | | 17700057 | Failed to uninstall updates because the HAP is not pre-installed. | | 17700060 | The specified application cannot be uninstalled. | | 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | | 17700073 | Failed to install the HAP because an application with the same bundle name but different signature information exists on the device. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.camera'; let installParam: installer.InstallParam = { isKeepData: true, installFlag: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstallUpdates(bundleName, installParam) .then(() => { console.info('uninstallUpdates successfully.'); }).catch((error: BusinessError) => { console.error('uninstallUpdates failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.createAppClone12+ createAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise\; 创建应用分身,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_CLONE_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 待创建应用分身的包名。 | | createAppCloneParam | [createAppCloneParam](#createappcloneparam12) | 否 | 指定创建应用分身所需的其他参数,默认值:参照[createAppCloneParam](#createappcloneparam12)的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。返回创建的分身应用索引值。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_CLONE_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. | | 17700004 | The userId is invalid. | | 17700061 | The appIndex is not in valid range or already exists. | | 17700069 | The app does not support the creation of an appClone instance. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.camera'; let createAppCloneParam: installer.CreateAppCloneParam = { userId: 100, appIndex: 1, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.createAppClone(bundleName, createAppCloneParam) .then(() => { console.info('createAppClone successfully.'); }).catch((error: BusinessError) => { console.error('createAppClone failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.destroyAppClone12+ destroyAppClone(bundleName: string, appIndex: number, userId?: number): Promise\; 删除应用分身,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.UNINSTALL_CLONE_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 待删除应用分身的包名。 | | appIndex | number | 是 | 待删除应用分身的索引。 | | userId | number | 否 | 待删除应用分身所属用户ID,可以通过[getOsAccountLocalId接口](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取。默认值:调用方所在用户。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.UNINSTALL_CLONE_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. | | 17700004 | The userId is invalid. | | 17700061 | The appIndex is invalid. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.camera'; let index = 1; let userId = 100; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.destroyAppClone(bundleName, index, userId) .then(() => { console.info('destroyAppClone successfully.'); }).catch((error: BusinessError) => { console.error('destroyAppClone failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.destroyAppClone15+ destroyAppClone(bundleName: string, appIndex: number, destroyAppCloneParam?: DestroyAppCloneParam): Promise\; 删除应用分身,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.UNINSTALL_CLONE_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 待删除应用分身的包名。 | | appIndex | number | 是 | 待删除应用分身的索引。 | | destroyAppCloneParam | [DestroyAppCloneParam](#destroyappcloneparam15) | 否 | 指定删除应用分身所需的其他参数,默认值:参照[DestroyAppCloneParam](#destroyappcloneparam15)的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.UNINSTALL_CLONE_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. | | 17700004 | The userId is invalid. | | 17700061 | The appIndex is invalid. | | 17700062 | Failed to uninstall the app because the app is locked. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.camera'; let index = 1; let userId = 100; let key = 'ohos.bms.param.verifyUninstallRule'; let value = 'false'; let item: installer.Parameters = {key, value}; let destroyAppCloneOpt: installer.DestroyAppCloneParam = { userId: userId, parameters: [item] }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.destroyAppClone(bundleName, index, destroyAppCloneOpt) .then(() => { console.info('destroyAppClone successfully.'); }).catch((error: BusinessError) => { console.error('destroyAppClone failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.installPreexistingApp12+ installPreexistingApp(bundleName: string, userId?: number): Promise\; 安装应用,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | bundleName | string | 是 | 需要安装应用的包名。 | | userId | number | 否 | 需要安装应用的用户ID,可以通过[getOsAccountLocalId接口](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取,userId需要大于0。默认值:调用方所在用户。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| | 17700001 | The specified bundleName cannot be found. | | 17700004 | The userId is invalid. | | 17700071 | It is not allowed to install the enterprise bundle. | | 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@ohos.base'; let bundleName = 'com.ohos.camera'; let userId = 100; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.installPreexistingApp(bundleName, userId) .then(() => { console.info('installPreexistingApp successfully.'); }).catch((error: BusinessError) => { console.error('installPreexistingApp failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.installPlugin19+ installPlugin(hostBundleName: string, pluginFilePaths: Array\, pluginParam?: PluginParam): Promise\ 应用安装插件,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.INSTALL_PLUGIN_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | hostBundleName | string | 是 | 待安装插件的应用包名。 | | pluginFilePaths | Array\ | 是 | 存储插件程序包的路径。当传入多个文件路径或者一个目录时,需确保这些文件是同一插件程序的HSP,且这些HSP的签名需要保持一致。 | | pluginParam | [PluginParam](#pluginparam19) | 否 | 指定安装插件所需的参数,默认值:参照 [PluginParam](#pluginparam19) 的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.INSTALL_PLUGIN_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 17700001 | The specified hostBundleName cannot be found or the bundle is not installed by the specified user. | | 17700004 | The userId is invalid. | | 17700010 | Failed to install the plugin because the plugin fails to be parsed. | | 17700011 | Failed to install the plugin because the plugin signature fails to be verified. | | 17700012 | Failed to install the plugin because the HSP path is invalid or the HSP is too large. | | 17700015 | Failed to install the plugin because they have different configuration information. | | 17700016 | Failed to install the plugin because of insufficient system disk space. | | 17700017 | Failed to install the plugin since the version of the plugin to install is too early. | | 17700048 | Failed to install the plugin because the code signature verification is failed. | | 17700052 | Failed to install the plugin because debug bundle cannot be installed under non-developer mode. | | 17700073 | Failed to install the plugin because a plugin with the same bundle name but different signature information exists on the device. | | 17700087 | Failed to install the plugin because the current device does not support plugin. | | 17700088 | Failed to install the plugin because the host application lacks ohos.permission.kernel.SUPPORT_PLUGIN. | | 17700089 | Failed to install the plugin because the plugin id fails to be parsed. | | 17700090 | Failed to install the plugin because the plugin id fails to be verified. | | 17700091 | Failed to install the plugin because the plugin name is same as host bundle name. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let hostBundleName = 'com.example.application'; let pluginFilePaths = ['/data/bms_app_install/test.hsp']; let pluginParam : installer.PluginParam = { userId : 100, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.installPlugin(hostBundleName, pluginFilePaths, pluginParam) .then(() => { console.info('installPlugin successfully.'); }).catch((error: BusinessError) => { console.error('installPlugin failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('installPlugin failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## BundleInstaller.uninstallPlugin19+ uninstallPlugin(hostBundleName: string, pluginBundleName: string, pluginParam?: PluginParam): Promise\ 应用卸载插件,使用Promise异步回调。 **系统接口:** 此接口为系统接口。 **需要权限:** ohos.permission.UNINSTALL_PLUGIN_BUNDLE **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | | hostBundleName | string | 是 | 待卸载插件的应用包名。 | | pluginBundleName | string | 是 | 插件的包名。 | | pluginParam | [PluginParam](#pluginparam19) | 否 | 指定卸载插件所需的参数,默认值:参照 [PluginParam](#pluginparam19) 的默认值。 | **返回值:** | 类型 | 说明 | | --------------- | -------------------------------------- | | Promise\ | 无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 | 错误码ID | 错误信息 | | -------- | ----------------------------------- | | 201 | Calling interface without permission 'ohos.permission.UNINSTALL_PLUGIN_BUNDLE'. | | 202 | Permission verification failed. A non-system application calls a system API. | | 17700001 | The specified bundle name is not found. | | 17700004 | The user id is invalid. | | 17700092 | Failed to uninstall the plugin because the specified plugin is not found. | **示例:** ```ts import { installer } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; let hostBundleName = 'com.example.application'; let pluginBundleName = 'com.ohos.pluginDemo'; let pluginParam : installer.PluginParam = { userId : 100, }; try { installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstallPlugin(hostBundleName, pluginBundleName, pluginParam) .then(() => { console.info('uninstallPlugin successfully.'); }).catch((error: BusinessError) => { console.error('uninstallPlugin failed:' + error.message); }); }).catch((error: BusinessError) => { console.error('uninstallPlugin failed. Cause: ' + error.message); }); } catch (error) { let message = (error as BusinessError).message; console.error('getBundleInstaller failed. Cause: ' + message); } ``` ## HashParam 应用程序安装卸载哈希参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------- | ------ | ---------------- |------- | ---------------- | | moduleName | string | 否 | 否 | 应用程序模块名称。 | | hashValue | string | 否 | 否 | 哈希值。 | ## InstallParam 应用程序安装、卸载或恢复需指定的参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ------------------------------ | ------------------------------ | ------------------| ------------------ | ------------------ | | userId | number | 否 | 是 | 指示用户id,默认值:调用方所在用户,取值范围:大于等于0,可使用[queryOsAccountLocalIdFromProcess](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取当前进程所在用户。当安装、卸载或恢复一个驱动应用时,该参数会被忽略,会在所有用户下执行。 | | installFlag | number | 否 | 是 | 指示安装标志,枚举值:0x00:应用初次安装,0x01:应用覆盖安装,0x10:应用免安装,默认值为应用初次安装。 | | isKeepData | boolean | 否 | 是| 卸载时是否保留数据目录,默认值为false。true表示卸载时保留数据目录,false表示卸载时不保留数据目录。 | | hashParams | Array<[HashParam](#hashparam)> | 否 | 是| 哈希值参数,默认值为空。 | | crowdtestDeadline| number | 否 | 是 | 众测活动的截止日期,默认值为-1,表示无截止日期约束。 | | sharedBundleDirPaths10+ | Array\ | 否 | 是|共享包文件所在路径,默认值为空。 | | specifiedDistributionType10+ | string | 否 | 是|应用安装时指定的[分发类型](../../security/app-provision-structure.md),默认值为空,最大长度为128字节。该字段通常由操作系统运营方的应用市场指定。 | | additionalInfo10+ | string | 否 | 是|应用安装时的额外信息,默认值为空,最大长度为3000字节。该字段通常由操作系统运营方的应用市场在安装企业应用时指定,用于保存应用的额外信息。 | | verifyCodeParamsdeprecated | Array<[VerifyCodeParam](#verifycodeparamdeprecated)> | 否 | 是| 代码签名文件参数,默认值为空。 | | pgoParams11+ | Array<[PGOParam](#pgoparam11)> | 否 | 是| PGO配置文件参数,默认值为空。 | | parameters15+ | Array<[Parameters](#parameters15)> | 否 | 是| 扩展参数,Parameters类型的数组,默认值为空。Parameters.key取值支持:
- "ohos.bms.param.renameInstall":若对应value值为“true”,表示安装时使用共享目录将安装包从应用沙箱移动到安装目录,否则使用常规目录将安装包从应用沙箱拷贝到安装目录。
- "ohos.bms.param.enterpriseForAllUser":若对应value值为“true”,表示在安装企业应用时为所有用户安装。
- "ohos.bms.param.verifyUninstallRule":若对应value值为“true”,表示设置卸载处置规则,用于拦截应用卸载。
- "ohos.bms.param.enterpriseManifest":value值为json文件的沙箱路径,json文件用于存储应用的描述文件,包括应用包名等,该字段用于企业应用克隆场景。克隆时,若该json文件存在,则将旧机的应用安装包拷贝到新机进行安装。| ## UninstallParam10+ 共享包卸载需指定的参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ----------- | ------ | ---- |---- | ------------------------------------------------------------ | | bundleName | string | 否 | 否 | 共享包包名。 | | versionCode | number | 否 | 是 | 指示共享包的版本号。默认值:如果不填写versionCode,则卸载该包名的所有共享包。 | ## VerifyCodeParamdeprecated > 从API version 11开始不再维护,应用的代码签名文件将集成到安装包中,不再需要该接口来指定安装包的代码签名文件。 应用程序代码签名文件信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------- | ------ |------ | ---------------- | ---------------- | | moduleName | string | 否 | 否 | 应用程序模块名称。 | | signatureFilePath | string | 否 | 否 | 代码签名文件路径。 | ## PGOParam11+ PGO(Profile-guided Optimization)配置文件参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------- | ------ | ------ | ---------------- | ---------------- | | moduleName | string | 否 | 否 | 应用程序模块名称。 | | pgoFilePath | string | 否 | 否 | PGO配置文件路径。 | ## Parameters15+ 扩展参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------- | ------ |------ | ---------------- | ---------------- | | key | string | 否 | 否 | 扩展参数键。 | | value | string | 否 | 否 | 扩展参数值。 | ## CreateAppCloneParam12+ 创建分身应用可指定的参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ----------- | ------ | ---- |---- | ------------------------------------------------------------ | | userId | number | 否 | 是 | 指定创建分身应用所在的用户ID,可以通过[getOsAccountLocalId接口](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取。默认值:调用方所在用户。 | | appIndex | number | 否 | 是 | 指定创建分身应用的索引值。默认值:当前可用的最小索引值。 | ## DestroyAppCloneParam15+ 删除分身应用可指定的参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ----------- | ------ | ----| ---- | ------------------------------------------------------------ | | userId | number | 否 | 是 | 指定删除分身应用所在的用户ID,可以通过[getOsAccountLocalId接口](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取。默认值:调用方所在用户。 | | parameters | Array<[Parameters](#parameters15)> | 否 | 是 | 指定删除分身应用扩展参数,默认值为空。 | ## PluginParam19+ 插件应用安装、卸载的参数信息。 **系统能力:** SystemCapability.BundleManager.BundleFramework.Core **系统接口:** 此接口为系统接口。 | 名称 | 类型 | 只读 | 可选 | 说明 | | ----------- | ------ | ---- |---- | ------------------------------------------------------------ | | userId | number | 否 | 是 | 指定安装、卸载插件程序所在的用户ID,可以通过[getOsAccountLocalId接口](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取。默认值:调用方所在用户。 | | parameters | Array<[Parameters](#parameters15)> | 否 | 是 | 指定安装、卸载插件程序的扩展参数,默认值为空。 |