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