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