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