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