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