1e41f4b71Sopenharmony_ci# @ohos.bundle.installer (installer模块)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **说明:** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块为系统接口。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci在设备上安装、升级和卸载应用。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```js 14e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## 权限列表 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci| 权限 | 权限等级 | 描述 | 20e41f4b71Sopenharmony_ci| ------------------------------ | ----------- | ---------------- | 21e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_BUNDLE | system_core | 允许应用安装、卸载其他应用(除了企业相关应用,目前有企业InHouse应用,企业MDM应用和企业normal应用)。 | 22e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_ENTERPRISE_BUNDLE | system_core | 允许应用安装企业InHouse应用。 | 23e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE | system_core | 允许在企业设备上安装企业MDM应用包。 | 24e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE | system_core | 允许在企业设备上安装企业NORMAL应用包。 | 25e41f4b71Sopenharmony_ci| ohos.permission.UNINSTALL_BUNDLE | system_core | 允许应用卸载应用。 | 26e41f4b71Sopenharmony_ci| ohos.permission.RECOVER_BUNDLE | system_core | 允许应用恢复预置应用。 | 27e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_SELF_BUNDLE | system_core | 允许企业MDM应用在企业设备上自升级。| 28e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_INTERNALTESTING_BUNDLE | system_core | 允许应用安装开发者内测构建应用。| 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci权限等级参考[权限APL等级说明](../../security/AccessToken/app-permission-mgmt-overview.md#权限机制中的基本概念)。 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci## BundleInstaller.getBundleInstaller 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_cigetBundleInstaller(callback: AsyncCallback\<BundleInstaller>): void 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci获取BundleInstaller对象,使用callback形式返回结果。 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**参数:** 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 45e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 46e41f4b71Sopenharmony_ci| callback | AsyncCallback\<BundleInstaller> | 是 | 回调函数,获取BundleInstaller对象,err为null,data为获取到的BundleInstaller对象;否则为错误对象。 | 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci**错误码:** 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 53e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 54e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 55e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**示例:** 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci```ts 60e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 61e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_citry { 64e41f4b71Sopenharmony_ci installer.getBundleInstaller((err: BusinessError, data: installer.BundleInstaller) => { 65e41f4b71Sopenharmony_ci if (err) { 66e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed:' + err.message); 67e41f4b71Sopenharmony_ci } else { 68e41f4b71Sopenharmony_ci console.info('getBundleInstaller successfully'); 69e41f4b71Sopenharmony_ci } 70e41f4b71Sopenharmony_ci }); 71e41f4b71Sopenharmony_ci} catch (error) { 72e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 73e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed:' + message); 74e41f4b71Sopenharmony_ci} 75e41f4b71Sopenharmony_ci``` 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci## BundleInstaller.getBundleInstaller 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_cigetBundleInstaller(): Promise\<BundleInstaller> 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci获取BundleInstaller对象,使用callback形式返回结果。 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**返回值:** 88e41f4b71Sopenharmony_ci| 类型 | 说明 | 89e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------ | 90e41f4b71Sopenharmony_ci| Promise\<BundleInstaller> | Promise对象,返回BundleInstaller对象。 | 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**错误码:** 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 97e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 98e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**示例:** 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci```ts 103e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 104e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_citry { 107e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 108e41f4b71Sopenharmony_ci console.info('getBundleInstaller successfully.'); 109e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 110e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 111e41f4b71Sopenharmony_ci }); 112e41f4b71Sopenharmony_ci} catch (error) { 113e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 114e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 115e41f4b71Sopenharmony_ci} 116e41f4b71Sopenharmony_ci``` 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci## BundleInstaller.getBundleInstallerSync<sup>10+</sup> 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_cigetBundleInstallerSync(): BundleInstaller 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci获取并返回BundleInstaller对象。 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**返回值:** 129e41f4b71Sopenharmony_ci| 类型 | 说明 | 130e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------ | 131e41f4b71Sopenharmony_ci| BundleInstaller | 返回BundleInstaller对象。 | 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**错误码:** 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.bundle错误码](errorcode-bundle.md)。 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 138e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 139e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**示例:** 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci```ts 144e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 145e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_citry { 148e41f4b71Sopenharmony_ci installer.getBundleInstallerSync(); 149e41f4b71Sopenharmony_ci console.info('getBundleInstallerSync successfully.'); 150e41f4b71Sopenharmony_ci} catch (error) { 151e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 152e41f4b71Sopenharmony_ci console.error('getBundleInstallerSync failed. Cause: ' + message); 153e41f4b71Sopenharmony_ci} 154e41f4b71Sopenharmony_ci``` 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci## BundleInstaller.install 157e41f4b71Sopenharmony_ciinstall(hapFilePaths: Array<string>, installParam: InstallParam, callback: AsyncCallback<void>): void 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci以异步方法安装应用,使用callback形式返回结果。 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_BUNDLE<sup>10+</sup> 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE<sup>10+</sup> 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE<sup>10+</sup> 164e41f4b71Sopenharmony_ci> **说明:** 从API version 10起,可通过ohos.permission.INSTALL_ENTERPRISE_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限调用此接口。 165e41f4b71Sopenharmony_ci> 166e41f4b71Sopenharmony_ci> 安装企业应用需要ohos.permission.INSTALL_ENTERPRISE_BUNDLE权限。 167e41f4b71Sopenharmony_ci> 168e41f4b71Sopenharmony_ci> 安装企业NORMAL应用需要ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE或ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 169e41f4b71Sopenharmony_ci> 170e41f4b71Sopenharmony_ci> 安装企业MDM应用需要ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 171e41f4b71Sopenharmony_ci> 172e41f4b71Sopenharmony_ci> 安装普通应用需要ohos.permission.INSTALL_BUNDLE权限。 173e41f4b71Sopenharmony_ci> 174e41f4b71Sopenharmony_ci> 安装开发者内测构建应用需要ohos.permission.INSTALL_INTERNALTESTING_BUNDLE权限。 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**参数:** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 181e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 182e41f4b71Sopenharmony_ci| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | 183e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | 184e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,安装应用成功,err为null,否则为错误对象。 | 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**错误码:** 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 191e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 192e41f4b71Sopenharmony_ci| 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'. | 193e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 194e41f4b71Sopenharmony_ci| 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. | 195e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 196e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | 197e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | 198e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | 199e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. | 200e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. | 201e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | 202e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | 203e41f4b71Sopenharmony_ci| 17700031 | Failed to install the HAP because the overlay check of the HAP failed. | 204e41f4b71Sopenharmony_ci| 17700036 | Failed to install the HSP due to the lack of required permission. | 205e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | 206e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | 207e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | 208e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | 209e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | 210e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | 211e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. | 212e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | 213e41f4b71Sopenharmony_ci| 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. | 214e41f4b71Sopenharmony_ci| 17700054 | Failed to install the HAP because the HAP requests wrong permissions.| 215e41f4b71Sopenharmony_ci| 17700066 | Failed to install the HAP because installing the native package failed. | 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**示例:** 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci```ts 220e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 221e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; 224e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 225e41f4b71Sopenharmony_ci userId: 100, 226e41f4b71Sopenharmony_ci isKeepData: false, 227e41f4b71Sopenharmony_ci installFlag: 1, 228e41f4b71Sopenharmony_ci}; 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_citry { 231e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 232e41f4b71Sopenharmony_ci data.install(hapFilePaths, installParam, (err: BusinessError) => { 233e41f4b71Sopenharmony_ci if (err) { 234e41f4b71Sopenharmony_ci console.error('install failed:' + err.message); 235e41f4b71Sopenharmony_ci } else { 236e41f4b71Sopenharmony_ci console.info('install successfully.'); 237e41f4b71Sopenharmony_ci } 238e41f4b71Sopenharmony_ci }); 239e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 240e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 241e41f4b71Sopenharmony_ci }); 242e41f4b71Sopenharmony_ci} catch (error) { 243e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 244e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 245e41f4b71Sopenharmony_ci} 246e41f4b71Sopenharmony_ci``` 247e41f4b71Sopenharmony_ci## BundleInstaller.install 248e41f4b71Sopenharmony_ciinstall(hapFilePaths: Array<string>, callback: AsyncCallback<void>): void 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci以异步方法安装应用,使用callback形式返回结果。 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_BUNDLE<sup>10+</sup> 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE<sup>10+</sup> 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE<sup>10+</sup> 255e41f4b71Sopenharmony_ci> **说明:** 从API version 10起,可通过ohos.permission.INSTALL_ENTERPRISE_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限调用此接口。 256e41f4b71Sopenharmony_ci> 257e41f4b71Sopenharmony_ci> 安装企业应用需要ohos.permission.INSTALL_ENTERPRISE_BUNDLE权限。 258e41f4b71Sopenharmony_ci> 259e41f4b71Sopenharmony_ci> 安装企业NORMAL应用需要ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE或ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 260e41f4b71Sopenharmony_ci> 261e41f4b71Sopenharmony_ci> 安装企业MDM应用需要ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 262e41f4b71Sopenharmony_ci> 263e41f4b71Sopenharmony_ci> 安装普通应用需要ohos.permission.INSTALL_BUNDLE权限。 264e41f4b71Sopenharmony_ci> 265e41f4b71Sopenharmony_ci> 安装开发者内测构建应用需要ohos.permission.INSTALL_INTERNALTESTING_BUNDLE权限。 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**参数:** 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 272e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 273e41f4b71Sopenharmony_ci| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | 274e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,安装应用成功,err为null,否则为错误对象。 | 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci**错误码:** 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 281e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 282e41f4b71Sopenharmony_ci| 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'. | 283e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 284e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 285e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | 286e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | 287e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | 288e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. | 289e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. | 290e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | 291e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | 292e41f4b71Sopenharmony_ci| 17700031 | Failed to install the HAP because the overlay check of the HAP failed. | 293e41f4b71Sopenharmony_ci| 17700036 | Failed to install the HSP due to the lack of required permission. | 294e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | 295e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | 296e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | 297e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | 298e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | 299e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | 300e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. | 301e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | 302e41f4b71Sopenharmony_ci| 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. | 303e41f4b71Sopenharmony_ci| 17700054 | Failed to install the HAP because the HAP requests wrong permissions.| 304e41f4b71Sopenharmony_ci| 17700066 | Failed to install the HAP because installing the native package failed. | 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**示例:** 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci```ts 309e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 310e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_citry { 315e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 316e41f4b71Sopenharmony_ci data.install(hapFilePaths, (err: BusinessError) => { 317e41f4b71Sopenharmony_ci if (err) { 318e41f4b71Sopenharmony_ci console.error('install failed:' + err.message); 319e41f4b71Sopenharmony_ci } else { 320e41f4b71Sopenharmony_ci console.info('install successfully.'); 321e41f4b71Sopenharmony_ci } 322e41f4b71Sopenharmony_ci }); 323e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 324e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 325e41f4b71Sopenharmony_ci }); 326e41f4b71Sopenharmony_ci} catch (error) { 327e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 328e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 329e41f4b71Sopenharmony_ci} 330e41f4b71Sopenharmony_ci``` 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci## BundleInstaller.install 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ciinstall(hapFilePaths: Array\<string\>, installParam?: InstallParam) : Promise\<void\> 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci以异步方法安装应用,使用Promise形式返回结果。 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_BUNDLE<sup>10+</sup> 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE<sup>10+</sup> 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE<sup>10+</sup> 341e41f4b71Sopenharmony_ci> **说明:** 从API version 10起,可通过ohos.permission.INSTALL_ENTERPRISE_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE 或 ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限调用此接口。 342e41f4b71Sopenharmony_ci> 343e41f4b71Sopenharmony_ci> 安装企业应用需要ohos.permission.INSTALL_ENTERPRISE_BUNDLE权限。 344e41f4b71Sopenharmony_ci> 345e41f4b71Sopenharmony_ci> 安装企业NORMAL应用需要ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE或ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 346e41f4b71Sopenharmony_ci> 347e41f4b71Sopenharmony_ci> 安装企业MDM应用需要ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE权限。 348e41f4b71Sopenharmony_ci> 349e41f4b71Sopenharmony_ci> 安装普通应用需要ohos.permission.INSTALL_BUNDLE权限。 350e41f4b71Sopenharmony_ci> 351e41f4b71Sopenharmony_ci> 安装开发者内测构建应用需要ohos.permission.INSTALL_INTERNALTESTING_BUNDLE权限。 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci**参数:** 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 358e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 359e41f4b71Sopenharmony_ci| hapFilePaths | Array\<string\> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | 360e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**返回值:** 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci| 类型 | 说明 | 365e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 366e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**错误码:** 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 373e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 374e41f4b71Sopenharmony_ci| 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'. | 375e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 376e41f4b71Sopenharmony_ci| 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. | 377e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 378e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | 379e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | 380e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | 381e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. | 382e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. | 383e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | 384e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | 385e41f4b71Sopenharmony_ci| 17700031 | Failed to install the HAP because the overlay check of the HAP failed. | 386e41f4b71Sopenharmony_ci| 17700036 | Failed to install the HSP due to the lack of required permission. | 387e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | 388e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | 389e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | 390e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | 391e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | 392e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | 393e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. | 394e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | 395e41f4b71Sopenharmony_ci| 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. | 396e41f4b71Sopenharmony_ci| 17700054 | Failed to install the HAP because the HAP requests wrong permissions.| 397e41f4b71Sopenharmony_ci| 17700066 | Failed to install the HAP because installing the native package failed. | 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**示例:** 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci```ts 402e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 403e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; 406e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 407e41f4b71Sopenharmony_ci userId: 100, 408e41f4b71Sopenharmony_ci isKeepData: false, 409e41f4b71Sopenharmony_ci installFlag: 1, 410e41f4b71Sopenharmony_ci}; 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_citry { 413e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 414e41f4b71Sopenharmony_ci data.install(hapFilePaths, installParam) 415e41f4b71Sopenharmony_ci .then((data: void) => { 416e41f4b71Sopenharmony_ci console.info('install successfully: ' + JSON.stringify(data)); 417e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 418e41f4b71Sopenharmony_ci console.error('install failed:' + error.message); 419e41f4b71Sopenharmony_ci }); 420e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 421e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 422e41f4b71Sopenharmony_ci }); 423e41f4b71Sopenharmony_ci} catch (error) { 424e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 425e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 426e41f4b71Sopenharmony_ci} 427e41f4b71Sopenharmony_ci``` 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci## BundleInstaller.uninstall 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ciuninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci以异步方法卸载应用,使用callback形式返回结果。 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**参数:** 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 444e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 445e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待卸载应用的包名。 | 446e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | 447e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,卸载应用成功,err为null,否则为错误对象。 | 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**错误码:** 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 454e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 455e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | 456e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 457e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 458e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 459e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 460e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | 461e41f4b71Sopenharmony_ci| 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. | 462e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | 463e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. | 464e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci**示例:** 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci```ts 469e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 470e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo'; 473e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 474e41f4b71Sopenharmony_ci userId: 100, 475e41f4b71Sopenharmony_ci isKeepData: false, 476e41f4b71Sopenharmony_ci installFlag: 1 477e41f4b71Sopenharmony_ci}; 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_citry { 480e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 481e41f4b71Sopenharmony_ci data.uninstall(bundleName, installParam, (err: BusinessError) => { 482e41f4b71Sopenharmony_ci if (err) { 483e41f4b71Sopenharmony_ci console.error('uninstall failed:' + err.message); 484e41f4b71Sopenharmony_ci } else { 485e41f4b71Sopenharmony_ci console.info('uninstall successfully.'); 486e41f4b71Sopenharmony_ci } 487e41f4b71Sopenharmony_ci }); 488e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 489e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 490e41f4b71Sopenharmony_ci }); 491e41f4b71Sopenharmony_ci} catch (error) { 492e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 493e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 494e41f4b71Sopenharmony_ci} 495e41f4b71Sopenharmony_ci``` 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci## BundleInstaller.uninstall 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciuninstall(bundleName: string, callback: AsyncCallback<void>): void 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci以异步方法卸载应用,使用callback形式返回结果。 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci**参数:** 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 512e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 513e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待卸载应用的包名。 | 514e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,卸载应用成功,err为null,否则为错误对象。 | 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci**错误码:** 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 521e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 522e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | 523e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 524e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 525e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 526e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | 527e41f4b71Sopenharmony_ci| 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. | 528e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | 529e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. | 530e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**示例:** 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci```ts 535e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 536e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo'; 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_citry { 541e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 542e41f4b71Sopenharmony_ci data.uninstall(bundleName, (err: BusinessError) => { 543e41f4b71Sopenharmony_ci if (err) { 544e41f4b71Sopenharmony_ci console.error('uninstall failed:' + err.message); 545e41f4b71Sopenharmony_ci } else { 546e41f4b71Sopenharmony_ci console.info('uninstall successfully.'); 547e41f4b71Sopenharmony_ci } 548e41f4b71Sopenharmony_ci }); 549e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 550e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 551e41f4b71Sopenharmony_ci }); 552e41f4b71Sopenharmony_ci} catch (error) { 553e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 554e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 555e41f4b71Sopenharmony_ci} 556e41f4b71Sopenharmony_ci``` 557e41f4b71Sopenharmony_ci## BundleInstaller.uninstall 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ciuninstall(bundleName: string, installParam?: InstallParam) : Promise\<void\> 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci以异步方法卸载应用,使用Promise形式返回结果。 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci**参数:** 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 572e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 573e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待卸载应用的包名。 | 574e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci**返回值:** 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci| 类型 | 说明 | 579e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 580e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 581e41f4b71Sopenharmony_ci 582e41f4b71Sopenharmony_ci**错误码:** 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 587e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 588e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | 589e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 590e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 591e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 592e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 593e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | 594e41f4b71Sopenharmony_ci| 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. | 595e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | 596e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. | 597e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci**示例:** 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci```ts 602e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 603e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo'; 606e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 607e41f4b71Sopenharmony_ci userId: 100, 608e41f4b71Sopenharmony_ci isKeepData: false, 609e41f4b71Sopenharmony_ci installFlag: 1, 610e41f4b71Sopenharmony_ci}; 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_citry { 613e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 614e41f4b71Sopenharmony_ci data.uninstall(bundleName, installParam) 615e41f4b71Sopenharmony_ci .then((data: void) => { 616e41f4b71Sopenharmony_ci console.info('uninstall successfully: ' + JSON.stringify(data)); 617e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 618e41f4b71Sopenharmony_ci console.error('uninstall failed:' + error.message); 619e41f4b71Sopenharmony_ci }); 620e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 621e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 622e41f4b71Sopenharmony_ci }); 623e41f4b71Sopenharmony_ci} catch (error) { 624e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 625e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 626e41f4b71Sopenharmony_ci} 627e41f4b71Sopenharmony_ci``` 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci## BundleInstaller.recover 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_cirecover(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci以异步方法回滚应用到初次安装时的状态,使用callback形式返回结果。 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 636e41f4b71Sopenharmony_ci 637e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci**参数:** 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 644e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 645e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待恢复应用的包名。 | 646e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | 647e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,回滚应用成功,err为null,否则为错误对象。 | 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ci**错误码:** 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 654e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 655e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. | 656e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 657e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 658e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 659e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 660e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci**示例:** 663e41f4b71Sopenharmony_ci 664e41f4b71Sopenharmony_ci```ts 665e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 666e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo'; 669e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 670e41f4b71Sopenharmony_ci userId: 100, 671e41f4b71Sopenharmony_ci isKeepData: false, 672e41f4b71Sopenharmony_ci installFlag: 1 673e41f4b71Sopenharmony_ci}; 674e41f4b71Sopenharmony_ci 675e41f4b71Sopenharmony_citry { 676e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 677e41f4b71Sopenharmony_ci data.recover(bundleName, installParam, (err: BusinessError) => { 678e41f4b71Sopenharmony_ci if (err) { 679e41f4b71Sopenharmony_ci console.error('recover failed:' + err.message); 680e41f4b71Sopenharmony_ci } else { 681e41f4b71Sopenharmony_ci console.info('recover successfully.'); 682e41f4b71Sopenharmony_ci } 683e41f4b71Sopenharmony_ci }); 684e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 685e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 686e41f4b71Sopenharmony_ci }); 687e41f4b71Sopenharmony_ci} catch (error) { 688e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 689e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 690e41f4b71Sopenharmony_ci} 691e41f4b71Sopenharmony_ci``` 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci 694e41f4b71Sopenharmony_ci## BundleInstaller.recover 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_cirecover(bundleName: string, callback: AsyncCallback<void>): void 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci以异步方法回滚应用到初次安装时的状态,使用callback形式返回结果。 699e41f4b71Sopenharmony_ci 700e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 701e41f4b71Sopenharmony_ci 702e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_ci**参数:** 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 709e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- | 710e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待恢复应用的包名。 | 711e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,回滚应用成功,err为null,否则为错误对象。 | 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**错误码:** 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 718e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 719e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. | 720e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 721e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 722e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 723e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | 724e41f4b71Sopenharmony_ci 725e41f4b71Sopenharmony_ci**示例:** 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci```ts 728e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 729e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo'; 732e41f4b71Sopenharmony_ci 733e41f4b71Sopenharmony_citry { 734e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 735e41f4b71Sopenharmony_ci data.recover(bundleName, (err: BusinessError) => { 736e41f4b71Sopenharmony_ci if (err) { 737e41f4b71Sopenharmony_ci console.error('recover failed:' + err.message); 738e41f4b71Sopenharmony_ci } else { 739e41f4b71Sopenharmony_ci console.info('recover successfully.'); 740e41f4b71Sopenharmony_ci } 741e41f4b71Sopenharmony_ci }); 742e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 743e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 744e41f4b71Sopenharmony_ci }); 745e41f4b71Sopenharmony_ci} catch (error) { 746e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 747e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 748e41f4b71Sopenharmony_ci} 749e41f4b71Sopenharmony_ci``` 750e41f4b71Sopenharmony_ci 751e41f4b71Sopenharmony_ci## BundleInstaller.recover 752e41f4b71Sopenharmony_ci 753e41f4b71Sopenharmony_cirecover(bundleName: string, installParam?: InstallParam) : Promise\<void\> 754e41f4b71Sopenharmony_ci 755e41f4b71Sopenharmony_ci以异步方法回滚应用到初次安装时的状态,使用Promise形式返回结果。 756e41f4b71Sopenharmony_ci 757e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**参数:** 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 766e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 767e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待卸载应用的包名。 | 768e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci**返回值:** 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_ci| 类型 | 说明 | 773e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 774e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 775e41f4b71Sopenharmony_ci 776e41f4b71Sopenharmony_ci**错误码:** 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 781e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 782e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. | 783e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 784e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 785e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 786e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 787e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci**示例:** 790e41f4b71Sopenharmony_ci```ts 791e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 792e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 793e41f4b71Sopenharmony_ci 794e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo'; 795e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 796e41f4b71Sopenharmony_ci userId: 100, 797e41f4b71Sopenharmony_ci isKeepData: false, 798e41f4b71Sopenharmony_ci installFlag: 1, 799e41f4b71Sopenharmony_ci}; 800e41f4b71Sopenharmony_ci 801e41f4b71Sopenharmony_citry { 802e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 803e41f4b71Sopenharmony_ci data.recover(bundleName, installParam) 804e41f4b71Sopenharmony_ci .then((data: void) => { 805e41f4b71Sopenharmony_ci console.info('recover successfully: ' + JSON.stringify(data)); 806e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 807e41f4b71Sopenharmony_ci console.error('recover failed:' + error.message); 808e41f4b71Sopenharmony_ci }); 809e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 810e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 811e41f4b71Sopenharmony_ci }); 812e41f4b71Sopenharmony_ci} catch (error) { 813e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 814e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 815e41f4b71Sopenharmony_ci} 816e41f4b71Sopenharmony_ci``` 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci## BundleInstaller.uninstall<sup>10+</sup> 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ciuninstall(uninstallParam: UninstallParam, callback : AsyncCallback\<void\>) : void 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci以异步方法卸载一个共享包,使用callback形式返回结果。 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE 827e41f4b71Sopenharmony_ci 828e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci**参数:** 831e41f4b71Sopenharmony_ci 832e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 833e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | -------------------------------------------------------- | 834e41f4b71Sopenharmony_ci| uninstallParam | [UninstallParam](#uninstallparam10) | 是 | 共享包卸载需指定的参数信息。 | 835e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,卸载应用成功,err为null,否则为错误对象。 | 836e41f4b71Sopenharmony_ci 837e41f4b71Sopenharmony_ci**错误码:** 838e41f4b71Sopenharmony_ci 839e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 842e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 843e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | 844e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 845e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 846e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | 847e41f4b71Sopenharmony_ci| 17700037 | The version of the shared bundle is dependent on other applications. | 848e41f4b71Sopenharmony_ci| 17700038 | The specified shared bundle does not exist. | 849e41f4b71Sopenharmony_ci 850e41f4b71Sopenharmony_ci**示例:** 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci```ts 853e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 854e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 855e41f4b71Sopenharmony_ci 856e41f4b71Sopenharmony_cilet uninstallParam: installer.UninstallParam = { 857e41f4b71Sopenharmony_ci bundleName: "com.ohos.demo", 858e41f4b71Sopenharmony_ci}; 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_citry { 861e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 862e41f4b71Sopenharmony_ci data.uninstall(uninstallParam, (err: BusinessError) => { 863e41f4b71Sopenharmony_ci if (err) { 864e41f4b71Sopenharmony_ci console.error('uninstall failed:' + err.message); 865e41f4b71Sopenharmony_ci } else { 866e41f4b71Sopenharmony_ci console.info('uninstall successfully.'); 867e41f4b71Sopenharmony_ci } 868e41f4b71Sopenharmony_ci }); 869e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 870e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 871e41f4b71Sopenharmony_ci }); 872e41f4b71Sopenharmony_ci} catch (error) { 873e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 874e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 875e41f4b71Sopenharmony_ci} 876e41f4b71Sopenharmony_ci``` 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_ci## BundleInstaller.uninstall<sup>10+</sup> 879e41f4b71Sopenharmony_ci 880e41f4b71Sopenharmony_ciuninstall(uninstallParam: UninstallParam) : Promise\<void> 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci以异步方法卸载一个共享包,使用Promise形式返回结果。 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.UNINSTALL_BUNDLE 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 889e41f4b71Sopenharmony_ci 890e41f4b71Sopenharmony_ci**参数:** 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 893e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | ---------------------------- | 894e41f4b71Sopenharmony_ci| uninstallParam | [UninstallParam](#uninstallparam10) | 是 | 共享包卸载需指定的参数信息。 | 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci**返回值:** 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_ci| 类型 | 说明 | 899e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- | 900e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ci**错误码:** 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 907e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 908e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | 909e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 910e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 911e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | 912e41f4b71Sopenharmony_ci| 17700037 | The version of the shared bundle is dependent on other applications. | 913e41f4b71Sopenharmony_ci| 17700038 | The specified shared bundle does not exist. | 914e41f4b71Sopenharmony_ci 915e41f4b71Sopenharmony_ci**示例:** 916e41f4b71Sopenharmony_ci 917e41f4b71Sopenharmony_ci```ts 918e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 919e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_cilet uninstallParam: installer.UninstallParam = { 922e41f4b71Sopenharmony_ci bundleName: "com.ohos.demo", 923e41f4b71Sopenharmony_ci}; 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_citry { 926e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 927e41f4b71Sopenharmony_ci data.uninstall(uninstallParam, (err: BusinessError) => { 928e41f4b71Sopenharmony_ci if (err) { 929e41f4b71Sopenharmony_ci console.error('uninstall failed:' + err.message); 930e41f4b71Sopenharmony_ci } else { 931e41f4b71Sopenharmony_ci console.info('uninstall successfully.'); 932e41f4b71Sopenharmony_ci } 933e41f4b71Sopenharmony_ci }); 934e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 935e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 936e41f4b71Sopenharmony_ci }); 937e41f4b71Sopenharmony_ci} catch (error) { 938e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 939e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 940e41f4b71Sopenharmony_ci} 941e41f4b71Sopenharmony_ci``` 942e41f4b71Sopenharmony_ci 943e41f4b71Sopenharmony_ci## BundleInstaller.addExtResource<sup>12+</sup> 944e41f4b71Sopenharmony_ci 945e41f4b71Sopenharmony_ciaddExtResource(bundleName: string, filePaths: Array\<string>): Promise\<void>; 946e41f4b71Sopenharmony_ci 947e41f4b71Sopenharmony_ci根据给定的bundleName和hsp文件路径添加扩展资源,使用Promise形式返回结果。 948e41f4b71Sopenharmony_ci 949e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 950e41f4b71Sopenharmony_ci 951e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 952e41f4b71Sopenharmony_ci 953e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 954e41f4b71Sopenharmony_ci 955e41f4b71Sopenharmony_ci**参数:** 956e41f4b71Sopenharmony_ci 957e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 958e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | ---------------------------- | 959e41f4b71Sopenharmony_ci| bundleName | string | 是 | 要添加扩展资源的应用名称。 | 960e41f4b71Sopenharmony_ci| filePaths | Array\<string> | 是 | 要添加扩展资源的资源路径。 | 961e41f4b71Sopenharmony_ci 962e41f4b71Sopenharmony_ci**返回值:** 963e41f4b71Sopenharmony_ci 964e41f4b71Sopenharmony_ci| 类型 | 说明 | 965e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- | 966e41f4b71Sopenharmony_ci| Promise\<void> | 无返回结果的Promise对象。 | 967e41f4b71Sopenharmony_ci 968e41f4b71Sopenharmony_ci**错误码:** 969e41f4b71Sopenharmony_ci 970e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 971e41f4b71Sopenharmony_ci 972e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 973e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 974e41f4b71Sopenharmony_ci| 201 | Permission denied. | 975e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 976e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 977e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName is not found. | 978e41f4b71Sopenharmony_ci| 17700301 | Failed to add extended resources. | 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci**示例:** 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci```ts 983e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 984e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog'; 985e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 986e41f4b71Sopenharmony_ci 987e41f4b71Sopenharmony_cilet bundleName : string = 'com.ohos.demo'; 988e41f4b71Sopenharmony_cilet filePaths : Array<string> = ['/data/storage/el2/base/a.hsp']; 989e41f4b71Sopenharmony_citry { 990e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 991e41f4b71Sopenharmony_ci data.addExtResource(bundleName, filePaths).then((data) => { 992e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'addExtResource successfully'); 993e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 994e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'addExtResource failed. Cause: %{public}s', err.message); 995e41f4b71Sopenharmony_ci }); 996e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 997e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 998e41f4b71Sopenharmony_ci }); 999e41f4b71Sopenharmony_ci} catch (error) { 1000e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1001e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1002e41f4b71Sopenharmony_ci} 1003e41f4b71Sopenharmony_ci``` 1004e41f4b71Sopenharmony_ci 1005e41f4b71Sopenharmony_ci## BundleInstaller.removeExtResource<sup>12+</sup> 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ciremoveExtResource(bundleName: string, moduleNames: Array\<string>): Promise\<void>; 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ci根据给定的bundleName和moduleNames删除扩展资源,使用Promise形式返回结果。 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1012e41f4b71Sopenharmony_ci 1013e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE 1014e41f4b71Sopenharmony_ci 1015e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ci**参数:** 1018e41f4b71Sopenharmony_ci 1019e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1020e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | ---------------------------- | 1021e41f4b71Sopenharmony_ci| bundleName | string | 是 | 要删除扩展资源的应用名称。 | 1022e41f4b71Sopenharmony_ci| moduleNames | Array\<string> | 是 | 要删除扩展资源的moduleNames。 | 1023e41f4b71Sopenharmony_ci 1024e41f4b71Sopenharmony_ci**返回值:** 1025e41f4b71Sopenharmony_ci 1026e41f4b71Sopenharmony_ci| 类型 | 说明 | 1027e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- | 1028e41f4b71Sopenharmony_ci| Promise\<void> | 无返回结果的Promise对象。 | 1029e41f4b71Sopenharmony_ci 1030e41f4b71Sopenharmony_ci**错误码:** 1031e41f4b71Sopenharmony_ci 1032e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1033e41f4b71Sopenharmony_ci 1034e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1035e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 1036e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1037e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1038e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1039e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName is not found. | 1040e41f4b71Sopenharmony_ci| 17700302 | Failed to remove extended resources. | 1041e41f4b71Sopenharmony_ci 1042e41f4b71Sopenharmony_ci**示例:** 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ci```ts 1045e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1046e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog'; 1047e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_cilet bundleName : string = 'com.ohos.demo'; 1050e41f4b71Sopenharmony_cilet moduleNames : Array<string> = ['moduleTest']; 1051e41f4b71Sopenharmony_citry { 1052e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1053e41f4b71Sopenharmony_ci data.removeExtResource(bundleName, moduleNames).then((data) => { 1054e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'removeExtResource successfully'); 1055e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1056e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'removeExtResource failed. Cause: %{public}s', err.message); 1057e41f4b71Sopenharmony_ci }); 1058e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1059e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1060e41f4b71Sopenharmony_ci }); 1061e41f4b71Sopenharmony_ci} catch (error) { 1062e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1063e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1064e41f4b71Sopenharmony_ci} 1065e41f4b71Sopenharmony_ci``` 1066e41f4b71Sopenharmony_ci 1067e41f4b71Sopenharmony_ci## BundleInstaller.updateBundleForSelf<sup>10+</sup> 1068e41f4b71Sopenharmony_ci 1069e41f4b71Sopenharmony_ciupdateBundleForSelf(hapFilePaths: Array\<string\>, installParam: InstallParam, callback: AsyncCallback\<void\>): void 1070e41f4b71Sopenharmony_ci 1071e41f4b71Sopenharmony_ci以异步方法更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用callback形式返回结果。 1072e41f4b71Sopenharmony_ci 1073e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_SELF_BUNDLE 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci**参数:** 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1082e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 1083e41f4b71Sopenharmony_ci| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | 1084e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 是 | 指定安装所需的其他参数。 | 1085e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,安装应用成功,err为null,否则为错误对象。 | 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci**错误码:** 1088e41f4b71Sopenharmony_ci 1089e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1092e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 1093e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. | 1094e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1095e41f4b71Sopenharmony_ci| 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. | 1096e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 1097e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | 1098e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | 1099e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | 1100e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. | 1101e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. | 1102e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | 1103e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | 1104e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | 1105e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | 1106e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | 1107e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | 1108e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | 1109e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | 1110e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. | 1111e41f4b71Sopenharmony_ci| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | 1112e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | 1113e41f4b71Sopenharmony_ci| 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. | 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**示例:** 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci```ts 1118e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1119e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; 1122e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 1123e41f4b71Sopenharmony_ci userId: 100, 1124e41f4b71Sopenharmony_ci isKeepData: false, 1125e41f4b71Sopenharmony_ci installFlag: 1, 1126e41f4b71Sopenharmony_ci}; 1127e41f4b71Sopenharmony_ci 1128e41f4b71Sopenharmony_citry { 1129e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1130e41f4b71Sopenharmony_ci data.updateBundleForSelf(hapFilePaths, installParam, (err: BusinessError) => { 1131e41f4b71Sopenharmony_ci if (err) { 1132e41f4b71Sopenharmony_ci console.error('updateBundleForSelf failed:' + err.message); 1133e41f4b71Sopenharmony_ci } else { 1134e41f4b71Sopenharmony_ci console.info('updateBundleForSelf successfully.'); 1135e41f4b71Sopenharmony_ci } 1136e41f4b71Sopenharmony_ci }); 1137e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1138e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1139e41f4b71Sopenharmony_ci }); 1140e41f4b71Sopenharmony_ci} catch (error) { 1141e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1142e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1143e41f4b71Sopenharmony_ci} 1144e41f4b71Sopenharmony_ci``` 1145e41f4b71Sopenharmony_ci 1146e41f4b71Sopenharmony_ci## BundleInstaller.updateBundleForSelf<sup>10+</sup> 1147e41f4b71Sopenharmony_ci 1148e41f4b71Sopenharmony_ciupdateBundleForSelf(hapFilePaths: Array\<string\>, callback: AsyncCallback\<void\>): void 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ci以异步方法更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用callback形式返回结果。 1151e41f4b71Sopenharmony_ci 1152e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1153e41f4b71Sopenharmony_ci 1154e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_SELF_BUNDLE 1155e41f4b71Sopenharmony_ci 1156e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1157e41f4b71Sopenharmony_ci 1158e41f4b71Sopenharmony_ci**参数:** 1159e41f4b71Sopenharmony_ci 1160e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1161e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 1162e41f4b71Sopenharmony_ci| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | 1163e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,安装应用成功,err为null,否则为错误对象。 | 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci**错误码:** 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1170e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 1171e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. | 1172e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1173e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1174e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | 1175e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | 1176e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | 1177e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. | 1178e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. | 1179e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | 1180e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | 1181e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | 1182e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | 1183e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | 1184e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | 1185e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | 1186e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | 1187e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. | 1188e41f4b71Sopenharmony_ci| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | 1189e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | 1190e41f4b71Sopenharmony_ci| 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. | 1191e41f4b71Sopenharmony_ci 1192e41f4b71Sopenharmony_ci**示例:** 1193e41f4b71Sopenharmony_ci 1194e41f4b71Sopenharmony_ci```ts 1195e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1196e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1197e41f4b71Sopenharmony_ci 1198e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; 1199e41f4b71Sopenharmony_ci 1200e41f4b71Sopenharmony_citry { 1201e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1202e41f4b71Sopenharmony_ci data.updateBundleForSelf(hapFilePaths, (err: BusinessError) => { 1203e41f4b71Sopenharmony_ci if (err) { 1204e41f4b71Sopenharmony_ci console.error('updateBundleForSelf failed:' + err.message); 1205e41f4b71Sopenharmony_ci } else { 1206e41f4b71Sopenharmony_ci console.info('updateBundleForSelf successfully.'); 1207e41f4b71Sopenharmony_ci } 1208e41f4b71Sopenharmony_ci }); 1209e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1210e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1211e41f4b71Sopenharmony_ci }); 1212e41f4b71Sopenharmony_ci} catch (error) { 1213e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1214e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1215e41f4b71Sopenharmony_ci} 1216e41f4b71Sopenharmony_ci``` 1217e41f4b71Sopenharmony_ci 1218e41f4b71Sopenharmony_ci## BundleInstaller.updateBundleForSelf<sup>10+</sup> 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ciupdateBundleForSelf(hapFilePaths: Array\<string\>, installParam?: InstallParam): Promise\<void\> 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci以异步方法更新当前应用,仅限企业设备上的企业MDM应用调用,且传入的hapFilePaths中的hap必须都属于当前应用,使用promise形式返回结果。 1223e41f4b71Sopenharmony_ci 1224e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1225e41f4b71Sopenharmony_ci 1226e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_SELF_BUNDLE 1227e41f4b71Sopenharmony_ci 1228e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1229e41f4b71Sopenharmony_ci 1230e41f4b71Sopenharmony_ci**参数:** 1231e41f4b71Sopenharmony_ci 1232e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1233e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 1234e41f4b71Sopenharmony_ci| hapFilePaths | Array<string> | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | 1235e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。 | 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci**返回值:** 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci| 类型 | 说明 | 1240e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- | 1241e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 1242e41f4b71Sopenharmony_ci 1243e41f4b71Sopenharmony_ci**错误码:** 1244e41f4b71Sopenharmony_ci 1245e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1246e41f4b71Sopenharmony_ci 1247e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1248e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 1249e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. | 1250e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1251e41f4b71Sopenharmony_ci| 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. | 1252e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. | 1253e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | 1254e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | 1255e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | 1256e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. | 1257e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. | 1258e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | 1259e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. | 1260e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. | 1261e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. | 1262e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. | 1263e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). | 1264e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. | 1265e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. | 1266e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. | 1267e41f4b71Sopenharmony_ci| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. | 1268e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. | 1269e41f4b71Sopenharmony_ci| 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. | 1270e41f4b71Sopenharmony_ci 1271e41f4b71Sopenharmony_ci**示例:** 1272e41f4b71Sopenharmony_ci 1273e41f4b71Sopenharmony_ci```ts 1274e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1275e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; 1278e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 1279e41f4b71Sopenharmony_ci userId: 100, 1280e41f4b71Sopenharmony_ci isKeepData: false, 1281e41f4b71Sopenharmony_ci installFlag: 1, 1282e41f4b71Sopenharmony_ci}; 1283e41f4b71Sopenharmony_ci 1284e41f4b71Sopenharmony_citry { 1285e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1286e41f4b71Sopenharmony_ci data.updateBundleForSelf(hapFilePaths, installParam) 1287e41f4b71Sopenharmony_ci .then((data: void) => { 1288e41f4b71Sopenharmony_ci console.info('updateBundleForSelf successfully: ' + JSON.stringify(data)); 1289e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1290e41f4b71Sopenharmony_ci console.error('updateBundleForSelf failed:' + error.message); 1291e41f4b71Sopenharmony_ci }); 1292e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1293e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1294e41f4b71Sopenharmony_ci }); 1295e41f4b71Sopenharmony_ci} catch (error) { 1296e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1297e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1298e41f4b71Sopenharmony_ci} 1299e41f4b71Sopenharmony_ci``` 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_ci## BundleInstaller.uninstallUpdates<sup>12+</sup> 1302e41f4b71Sopenharmony_ci 1303e41f4b71Sopenharmony_ciuninstallUpdates(bundleName: string, installParam?: InstallParam): Promise\<void\>; 1304e41f4b71Sopenharmony_ci 1305e41f4b71Sopenharmony_ci以异步方法对预置应用进行卸载更新,恢复到初次安装时的状态,使用Promise形式返回结果。 1306e41f4b71Sopenharmony_ci 1307e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1308e41f4b71Sopenharmony_ci 1309e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 或 ohos.permission.RECOVER_BUNDLE 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1312e41f4b71Sopenharmony_ci 1313e41f4b71Sopenharmony_ci**参数:** 1314e41f4b71Sopenharmony_ci 1315e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1316e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 1317e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待卸载更新应用的包名。 | 1318e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | 否 | 指定卸载更新所需的其他参数,默认值:参照[InstallParam](#installparam)的默认值。其中userId无法指定,调用本接口将对所有已安装相应应用的用户进行卸载更新操作。 | 1319e41f4b71Sopenharmony_ci 1320e41f4b71Sopenharmony_ci**返回值:** 1321e41f4b71Sopenharmony_ci 1322e41f4b71Sopenharmony_ci| 类型 | 说明 | 1323e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 1324e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 1325e41f4b71Sopenharmony_ci 1326e41f4b71Sopenharmony_ci**错误码:** 1327e41f4b71Sopenharmony_ci 1328e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1329e41f4b71Sopenharmony_ci 1330e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1331e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1332e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. | 1333e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1334e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1335e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 1336e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. | 1337e41f4b71Sopenharmony_ci| 17700057 | Failed to uninstall updates because the HAP is not pre-installed. | 1338e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. | 1339e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. | 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_ci**示例:** 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ci```ts 1344e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1345e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1346e41f4b71Sopenharmony_ci 1347e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera'; 1348e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = { 1349e41f4b71Sopenharmony_ci isKeepData: true, 1350e41f4b71Sopenharmony_ci installFlag: 1, 1351e41f4b71Sopenharmony_ci}; 1352e41f4b71Sopenharmony_ci 1353e41f4b71Sopenharmony_citry { 1354e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1355e41f4b71Sopenharmony_ci data.uninstallUpdates(bundleName, installParam) 1356e41f4b71Sopenharmony_ci .then(() => { 1357e41f4b71Sopenharmony_ci console.info('uninstallUpdates successfully.'); 1358e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1359e41f4b71Sopenharmony_ci console.error('uninstallUpdates failed:' + error.message); 1360e41f4b71Sopenharmony_ci }); 1361e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1362e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1363e41f4b71Sopenharmony_ci }); 1364e41f4b71Sopenharmony_ci} catch (error) { 1365e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1366e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1367e41f4b71Sopenharmony_ci} 1368e41f4b71Sopenharmony_ci``` 1369e41f4b71Sopenharmony_ci 1370e41f4b71Sopenharmony_ci## BundleInstaller.createAppClone<sup>12+</sup> 1371e41f4b71Sopenharmony_ci 1372e41f4b71Sopenharmony_cicreateAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise\<number\>; 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci以异步方法创建应用分身,使用Promise形式返回结果。 1375e41f4b71Sopenharmony_ci 1376e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1377e41f4b71Sopenharmony_ci 1378e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_CLONE_BUNDLE 1379e41f4b71Sopenharmony_ci 1380e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1381e41f4b71Sopenharmony_ci 1382e41f4b71Sopenharmony_ci**参数:** 1383e41f4b71Sopenharmony_ci 1384e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1385e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 1386e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待创建应用分身的包名。 | 1387e41f4b71Sopenharmony_ci| createAppCloneParam | [createAppCloneParam](#createappcloneparam12) | 否 | 指定创建应用分身所需的其他参数,默认值:参照[createAppCloneParam](#createappcloneparam12)的默认值。 | 1388e41f4b71Sopenharmony_ci 1389e41f4b71Sopenharmony_ci**返回值:** 1390e41f4b71Sopenharmony_ci 1391e41f4b71Sopenharmony_ci| 类型 | 说明 | 1392e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 1393e41f4b71Sopenharmony_ci| Promise\<number\> | Promise对象。返回创建的分身应用索引值。 | 1394e41f4b71Sopenharmony_ci 1395e41f4b71Sopenharmony_ci**错误码:** 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1400e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1401e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_CLONE_BUNDLE'. | 1402e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1403e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1404e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. | 1405e41f4b71Sopenharmony_ci| 17700004 | The userId is invalid. | 1406e41f4b71Sopenharmony_ci| 17700061 | The appIndex is not in valid range or already exists. | 1407e41f4b71Sopenharmony_ci| 17700069 | The app does not support the creation of an appClone instance. | 1408e41f4b71Sopenharmony_ci 1409e41f4b71Sopenharmony_ci**示例:** 1410e41f4b71Sopenharmony_ci```ts 1411e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1412e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1413e41f4b71Sopenharmony_ci 1414e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera'; 1415e41f4b71Sopenharmony_cilet createAppCloneParam: installer.CreateAppCloneParam = { 1416e41f4b71Sopenharmony_ci userId: 100, 1417e41f4b71Sopenharmony_ci appIndex: 1, 1418e41f4b71Sopenharmony_ci}; 1419e41f4b71Sopenharmony_ci 1420e41f4b71Sopenharmony_citry { 1421e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1422e41f4b71Sopenharmony_ci data.createAppClone(bundleName, createAppCloneParam) 1423e41f4b71Sopenharmony_ci .then(() => { 1424e41f4b71Sopenharmony_ci console.info('createAppClone successfully.'); 1425e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1426e41f4b71Sopenharmony_ci console.error('createAppClone failed:' + error.message); 1427e41f4b71Sopenharmony_ci }); 1428e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1429e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1430e41f4b71Sopenharmony_ci }); 1431e41f4b71Sopenharmony_ci} catch (error) { 1432e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1433e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1434e41f4b71Sopenharmony_ci} 1435e41f4b71Sopenharmony_ci``` 1436e41f4b71Sopenharmony_ci 1437e41f4b71Sopenharmony_ci## BundleInstaller.destroyAppClone<sup>12+</sup> 1438e41f4b71Sopenharmony_ci 1439e41f4b71Sopenharmony_cidestroyAppClone(bundleName: string, appIndex: number, userId?: number): Promise\<void\>; 1440e41f4b71Sopenharmony_ci 1441e41f4b71Sopenharmony_ci以异步方法删除应用分身,使用Promise形式返回结果。 1442e41f4b71Sopenharmony_ci 1443e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1444e41f4b71Sopenharmony_ci 1445e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.UNINSTALL_CLONE_BUNDLE 1446e41f4b71Sopenharmony_ci 1447e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1448e41f4b71Sopenharmony_ci 1449e41f4b71Sopenharmony_ci**参数:** 1450e41f4b71Sopenharmony_ci 1451e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1452e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 1453e41f4b71Sopenharmony_ci| bundleName | string | 是 | 待删除应用分身的包名。 | 1454e41f4b71Sopenharmony_ci| appIndex | number | 是 | 待删除应用分身的索引。 | 1455e41f4b71Sopenharmony_ci| userId | number | 否 | 待删除应用分身所属用户id。默认值:调用方所在用户。 | 1456e41f4b71Sopenharmony_ci 1457e41f4b71Sopenharmony_ci**返回值:** 1458e41f4b71Sopenharmony_ci 1459e41f4b71Sopenharmony_ci| 类型 | 说明 | 1460e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 1461e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 1462e41f4b71Sopenharmony_ci 1463e41f4b71Sopenharmony_ci**错误码:** 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1466e41f4b71Sopenharmony_ci 1467e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1468e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1469e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.UNINSTALL_CLONE_BUNDLE'. | 1470e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1471e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1472e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. | 1473e41f4b71Sopenharmony_ci| 17700004 | The userId is invalid. | 1474e41f4b71Sopenharmony_ci| 17700061 | The appIndex is invalid. | 1475e41f4b71Sopenharmony_ci 1476e41f4b71Sopenharmony_ci**示例:** 1477e41f4b71Sopenharmony_ci```ts 1478e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1479e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera'; 1482e41f4b71Sopenharmony_cilet index = 1; 1483e41f4b71Sopenharmony_cilet userId = 100; 1484e41f4b71Sopenharmony_ci 1485e41f4b71Sopenharmony_citry { 1486e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1487e41f4b71Sopenharmony_ci data.destroyAppClone(bundleName, index, userId) 1488e41f4b71Sopenharmony_ci .then(() => { 1489e41f4b71Sopenharmony_ci console.info('destroyAppClone successfully.'); 1490e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1491e41f4b71Sopenharmony_ci console.error('destroyAppClone failed:' + error.message); 1492e41f4b71Sopenharmony_ci }); 1493e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1494e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1495e41f4b71Sopenharmony_ci }); 1496e41f4b71Sopenharmony_ci} catch (error) { 1497e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1498e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1499e41f4b71Sopenharmony_ci} 1500e41f4b71Sopenharmony_ci``` 1501e41f4b71Sopenharmony_ci 1502e41f4b71Sopenharmony_ci## BundleInstaller.installPreexistingApp<sup>12+</sup> 1503e41f4b71Sopenharmony_ci 1504e41f4b71Sopenharmony_ciinstallPreexistingApp(bundleName: string, userId?: number): Promise\<void\>; 1505e41f4b71Sopenharmony_ci 1506e41f4b71Sopenharmony_ci以异步方法安装应用,使用Promise形式返回结果。 1507e41f4b71Sopenharmony_ci 1508e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 1509e41f4b71Sopenharmony_ci 1510e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.INSTALL_BUNDLE 1511e41f4b71Sopenharmony_ci 1512e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ci**参数:** 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1517e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | 1518e41f4b71Sopenharmony_ci| bundleName | string | 是 | 需要安装应用的包名。 | 1519e41f4b71Sopenharmony_ci| userId | number | 否 | 需要安装应用的用户id,userId需要大于0。默认值:调用方所在用户。 | 1520e41f4b71Sopenharmony_ci 1521e41f4b71Sopenharmony_ci**返回值:** 1522e41f4b71Sopenharmony_ci 1523e41f4b71Sopenharmony_ci| 类型 | 说明 | 1524e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | 1525e41f4b71Sopenharmony_ci| Promise\<void\> | Promise对象。无返回结果的Promise对象。 | 1526e41f4b71Sopenharmony_ci 1527e41f4b71Sopenharmony_ci**错误码:** 1528e41f4b71Sopenharmony_ci 1529e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[ohos.bundle错误码](errorcode-bundle.md)。 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1532e41f4b71Sopenharmony_ci| -------- | ----------------------------------- | 1533e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE'. | 1534e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 1535e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 1536e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName cannot be found. | 1537e41f4b71Sopenharmony_ci| 17700004 | The userId is invalid. | 1538e41f4b71Sopenharmony_ci| 17700071 | It is not allowed to install the enterprise bundle. | 1539e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. | 1540e41f4b71Sopenharmony_ci 1541e41f4b71Sopenharmony_ci**示例:** 1542e41f4b71Sopenharmony_ci```ts 1543e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer'; 1544e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 1545e41f4b71Sopenharmony_ci 1546e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera'; 1547e41f4b71Sopenharmony_cilet userId = 100; 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_citry { 1550e41f4b71Sopenharmony_ci installer.getBundleInstaller().then((data: installer.BundleInstaller) => { 1551e41f4b71Sopenharmony_ci data.installPreexistingApp(bundleName, userId) 1552e41f4b71Sopenharmony_ci .then(() => { 1553e41f4b71Sopenharmony_ci console.info('installPreexistingApp successfully.'); 1554e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1555e41f4b71Sopenharmony_ci console.error('installPreexistingApp failed:' + error.message); 1556e41f4b71Sopenharmony_ci }); 1557e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 1558e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + error.message); 1559e41f4b71Sopenharmony_ci }); 1560e41f4b71Sopenharmony_ci} catch (error) { 1561e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 1562e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 1563e41f4b71Sopenharmony_ci} 1564e41f4b71Sopenharmony_ci``` 1565e41f4b71Sopenharmony_ci 1566e41f4b71Sopenharmony_ci## HashParam 1567e41f4b71Sopenharmony_ci 1568e41f4b71Sopenharmony_ci应用程序安装卸载哈希参数信息。 1569e41f4b71Sopenharmony_ci 1570e41f4b71Sopenharmony_ci **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1571e41f4b71Sopenharmony_ci 1572e41f4b71Sopenharmony_ci **系统接口:** 此接口为系统接口。 1573e41f4b71Sopenharmony_ci 1574e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1575e41f4b71Sopenharmony_ci| ---------- | ------ | ---------------- | ---------------- | 1576e41f4b71Sopenharmony_ci| moduleName | string | 是 | 应用程序模块名称。 | 1577e41f4b71Sopenharmony_ci| hashValue | string | 是 | 哈希值。 | 1578e41f4b71Sopenharmony_ci 1579e41f4b71Sopenharmony_ci## InstallParam 1580e41f4b71Sopenharmony_ci 1581e41f4b71Sopenharmony_ci应用程序安装、卸载或恢复需指定的参数信息。 1582e41f4b71Sopenharmony_ci 1583e41f4b71Sopenharmony_ci **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1584e41f4b71Sopenharmony_ci 1585e41f4b71Sopenharmony_ci **系统接口:** 此接口为系统接口。 1586e41f4b71Sopenharmony_ci 1587e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1588e41f4b71Sopenharmony_ci| ------------------------------ | ------------------------------ | ------------------ | ------------------ | 1589e41f4b71Sopenharmony_ci| userId | number | 否 | 指示用户id,默认值:调用方所在用户,取值范围:大于等于0,可使用[queryOsAccountLocalIdFromProcess](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9)获取当前进程所在用户。当安装、卸载或恢复一个驱动应用时,该参数会被忽略,会在所有用户下执行。 | 1590e41f4b71Sopenharmony_ci| installFlag | number | 否 | 指示安装标志,枚举值:0x00:应用初次安装,0x01:应用覆盖安装,0x10:应用免安装,默认值为应用初次安装。 | 1591e41f4b71Sopenharmony_ci| isKeepData | boolean | 否 | 卸载时是否保留数据目录,默认值为false。 | 1592e41f4b71Sopenharmony_ci| hashParams | Array<[HashParam](#hashparam)> | 否 | 哈希值参数,默认值为空。 | 1593e41f4b71Sopenharmony_ci| crowdtestDeadline| number | 否 | 众测活动的截止日期,默认值为-1,表示无截止日期约束。 | 1594e41f4b71Sopenharmony_ci| sharedBundleDirPaths<sup>10+</sup> | Array\<String> | 否 |共享包文件所在路径,默认值为空。 | 1595e41f4b71Sopenharmony_ci| specifiedDistributionType<sup>10+</sup> | string | 否 |应用安装时指定的分发类型,默认值为空,最大长度为128字节。该字段通常由操作系统运营方的应用市场指定。 | 1596e41f4b71Sopenharmony_ci| additionalInfo<sup>10+</sup> | string | 否 |应用安装时的额外信息,默认值为空,最大长度为3000字节。该字段通常由操作系统运营方的应用市场在安装企业应用时指定,用于保存应用的额外信息。 | 1597e41f4b71Sopenharmony_ci| verifyCodeParams<sup>deprecated<sup> | Array<[VerifyCodeParam](#verifycodeparamdeprecated)> | 否 | 代码签名文件参数,默认值为空。 | 1598e41f4b71Sopenharmony_ci| pgoParams<sup>11+</sup> | Array<[PGOParam](#pgoparam11)> | 否 | PGO配置文件参数,默认值为空。 | 1599e41f4b71Sopenharmony_ci 1600e41f4b71Sopenharmony_ci## UninstallParam<sup>10+</sup> 1601e41f4b71Sopenharmony_ci 1602e41f4b71Sopenharmony_ci共享包卸载需指定的参数信息。 1603e41f4b71Sopenharmony_ci 1604e41f4b71Sopenharmony_ci **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1605e41f4b71Sopenharmony_ci 1606e41f4b71Sopenharmony_ci **系统接口:** 此接口为系统接口。 1607e41f4b71Sopenharmony_ci 1608e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1609e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ------------------------------------------------------------ | 1610e41f4b71Sopenharmony_ci| bundleName | string | 是 | 共享包包名。 | 1611e41f4b71Sopenharmony_ci| versionCode | number | 否 | 指示共享包的版本号。默认值:如果不填写versionCode,则卸载该包名的所有共享包。 | 1612e41f4b71Sopenharmony_ci 1613e41f4b71Sopenharmony_ci## VerifyCodeParam<sup>deprecated<sup> 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_ci> 从API version 11开始不再维护,应用的代码签名文件将集成到安装包中,不再需要该接口来指定安装包的代码签名文件。 1616e41f4b71Sopenharmony_ci 1617e41f4b71Sopenharmony_ci应用程序代码签名文件信息。 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ci **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ci **系统接口:** 此接口为系统接口。 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1624e41f4b71Sopenharmony_ci| ---------- | ------ | ---------------- | ---------------- | 1625e41f4b71Sopenharmony_ci| moduleName | string | 是 | 应用程序模块名称。 | 1626e41f4b71Sopenharmony_ci| signatureFilePath | string | 是 | 代码签名文件路径。 | 1627e41f4b71Sopenharmony_ci 1628e41f4b71Sopenharmony_ci## PGOParam<sup>11+</sup> 1629e41f4b71Sopenharmony_ci 1630e41f4b71Sopenharmony_ciPGO(Profile-guided Optimization)配置文件参数信息。 1631e41f4b71Sopenharmony_ci 1632e41f4b71Sopenharmony_ci **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1633e41f4b71Sopenharmony_ci 1634e41f4b71Sopenharmony_ci **系统接口:** 此接口为系统接口。 1635e41f4b71Sopenharmony_ci 1636e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1637e41f4b71Sopenharmony_ci| ---------- | ------ | ---------------- | ---------------- | 1638e41f4b71Sopenharmony_ci| moduleName | string | 是 | 应用程序模块名称。 | 1639e41f4b71Sopenharmony_ci| pgoFilePath | string | 是 | PGO配置文件路径。 | 1640e41f4b71Sopenharmony_ci 1641e41f4b71Sopenharmony_ci## CreateAppCloneParam<sup>12+</sup> 1642e41f4b71Sopenharmony_ci 1643e41f4b71Sopenharmony_ci创建分身应用可指定的参数信息。 1644e41f4b71Sopenharmony_ci 1645e41f4b71Sopenharmony_ci **系统能力:** SystemCapability.BundleManager.BundleFramework.Core 1646e41f4b71Sopenharmony_ci 1647e41f4b71Sopenharmony_ci **系统接口:** 此接口为系统接口。 1648e41f4b71Sopenharmony_ci 1649e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1650e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ------------------------------------------------------------ | 1651e41f4b71Sopenharmony_ci| userId | number | 否 | 指定创建分身应用所在的用户id。默认值:调用方所在用户。 | 1652e41f4b71Sopenharmony_ci| appIndex | number | 否 | 指定创建分身应用的索引值。默认值:当前可用的最小索引值。 | 1653