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