diff --git a/zh-cn/application-dev/reference/apis/js-apis-installer.md b/zh-cn/application-dev/reference/apis/js-apis-installer.md index df80cf2b56aa0a1f13df81766814ad03cc0997c3..3bdaec160e24760052f305f4a710288c1594c8b1 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-installer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-installer.md @@ -146,6 +146,73 @@ try { } ``` +## BundleInstaller.install + +install(hapFilePaths: Array\, installParam?: InstallParam) : Promise\; + +以异步方法安装应用,使用Promise形式返回结果。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.INSTALL_BUNDLE + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| hapFilePaths | Array\ | 是 | 存储应用程序包的路径。路径应该是当前应用程序中存放HAP的数据目录。当传入的路径是一个目录时, 该目录下只能放同一个应用的HAP,且这些HAP的签名需要保持一致。 | +| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数。 | + +**返回值:** + +| 类型 | 说明 | +| --------------- | -------------------------------------- | +| Promise\ | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700004 | The specified user ID is not found. | +| 17700010 | Failed to install the HAP because the HAP fails to be parsed. | +| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. | +| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. | +| 17700015 | Failed to install the HAPs because they have different configuration information. | +| 17700016 | Failed to install the HAP because of insufficient system disk space. | +| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. | +| 17700018 | Failed to install because the dependent module does not exist. | + +**示例:** + +```ts +import installer from '@ohos.bundle.installer'; +let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; +let installParam = { + userId: 100, + isKeepData: false, + installFlag: 1, +}; + +try { + installer.getBundleInstaller().then(data => { + data.install(hapFilePaths, installParam) + .then((data) => { + console.info('install successfully: ' + JSON.stringify(data)); + }).catch((error) => { + console.error('install failed:' + error.message); + }); + }).catch(error => { + console.error('getBundleInstaller failed. Cause: ' + error.message); + }); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` + ## BundleInstaller.uninstall uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void; @@ -172,6 +239,7 @@ uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallbac | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | +| 17700001 | The specified bundle name is not found. | | 17700004 | The specified user ID is not found. | | 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | @@ -202,12 +270,72 @@ try { console.error('getBundleInstaller failed. Cause: ' + error.message); } ``` +## BundleInstaller.uninstall + +uninstall(bundleName: string, installParam?: InstallParam) : Promise\; + +以异步方法卸载应用,使用Promise形式返回结果。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.INSTALL_BUNDLE + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| bundleName | string | 是 | 待卸载应用的包名。 | +| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数。 | + +**返回值:** + +| 类型 | 说明 | +| --------------- | -------------------------------------- | +| Promise\ | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------------------ | +| 17700001 | The specified bundle name is not found. | +| 17700004 | The specified user ID is not found. | +| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. | + +**示例:** +```ts +import installer from '@ohos.bundle.installer'; +let bundleName = 'com.ohos.demo'; +let installParam = { + userId: 100, + isKeepData: false, + installFlag: 1, +}; + +try { + installer.getBundleInstaller().then(data => { + data.uninstall(bundleName, installParam) + .then((data) => { + console.info('uninstall successfully: ' + JSON.stringify(data)); + }).catch((error) => { + console.error('uninstall failed:' + error.message); + }); + }).catch(error => { + console.error('getBundleInstaller failed. Cause: ' + error.message); + }); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` ## BundleInstaller.recover recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback<void>): void; -以异步方法回滚应用,使用callback形式返回结果。 +以异步方法回滚应用到初次安装时的状态,使用callback形式返回结果。 **系统接口:** 此接口为系统接口,三方应用不支持调用 @@ -229,6 +357,7 @@ recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback& | 错误码ID | 错误信息 | | -------- | ----------------------------------- | +| 17700001 | The specified bundle name is not found. | | 17700004 | The specified user ID is not found. | **示例:** @@ -258,7 +387,65 @@ try { console.error('getBundleInstaller failed. Cause: ' + error.message); } ``` +## BundleInstaller.recover + +recover(bundleName: string, installParam?: InstallParam) : Promise\; + +以异步方法回滚应用到初次安装时的状态,使用Promise形式返回结果。 + +**系统接口:** 此接口为系统接口。 + +**需要权限:** ohos.permission.INSTALL_BUNDLE + +**系统能力:** SystemCapability.BundleManager.BundleFramework.Core +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ | +| bundleName | string | 是 | 待卸载应用的包名。 | +| installParam | [InstallParam](#installparam) | 否 | 指定安装所需的其他参数。 | + +**返回值:** + +| 类型 | 说明 | +| --------------- | -------------------------------------- | +| Promise\ | Promise对象。无返回结果的Promise对象。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.bundle错误码](../errorcodes/errorcode-bundle.md)。 + +| 错误码ID | 错误信息 | +| -------- | ----------------------------------- | +| 17700001 | The specified bundle name is not found. | +| 17700004 | The specified user ID is not found. | + +**示例:** +```ts +import installer from '@ohos.bundle.installer'; +let bundleName = 'com.ohos.demo'; +let installParam = { + userId: 100, + isKeepData: false, + installFlag: 1, +}; + +try { + installer.getBundleInstaller().then(data => { + data.recover(bundleName, installParam) + .then((data) => { + console.info('recover successfully: ' + JSON.stringify(data)); + }).catch((error) => { + console.error('recover failed:' + error.message); + }); + }).catch(error => { + console.error('getBundleInstaller failed. Cause: ' + error.message); + }); +} catch (error) { + console.error('getBundleInstaller failed. Cause: ' + error.message); +} +``` ## HashParam 应用程序安装卸载哈希参数信息。