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 95ea29e2378213b65cb0521c1aa99cdf72d5ff61..a68416bfaff40665ab8031473efd71db7bc21afb 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-installer.md +++ b/zh-cn/application-dev/reference/apis/js-apis-installer.md @@ -46,9 +46,10 @@ getBundleInstaller(callback: AsyncCallback\): void; ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; try { - installer.getBundleInstaller((err, data) => { + installer.getBundleInstaller((err: BusinessError, data: installer.BundleInstaller) => { if (err) { console.error('getBundleInstaller failed:' + err.message); } else { @@ -79,11 +80,12 @@ getBundleInstaller(): Promise\; ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; try { - installer.getBundleInstaller().then((data) => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { console.info('getBundleInstaller successfully.'); - }).catch((error) => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -176,23 +178,25 @@ install(hapFilePaths: Array<string>, installParam: InstallParam, callback: ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { - installer.getBundleInstaller().then(data => { - data.install(hapFilePaths, installParam, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.install(hapFilePaths, installParam, (err: BusinessError) => { if (err) { console.error('install failed:' + err.message); } else { console.info('install successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -254,11 +258,13 @@ install(hapFilePaths: Array<string>, callback: AsyncCallback<void>): ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; try { - installer.getBundleInstaller().then(data => { - data.install(hapFilePaths, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.install(hapFilePaths, (err: BusinessError) => { if (err) { console.error('install failed:' + err.message); } else { @@ -336,22 +342,24 @@ install(hapFilePaths: Array\, installParam?: InstallParam) : Promise\ { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.install(hapFilePaths, installParam) - .then((data) => { + .then((data: void) => { console.info('install successfully: ' + JSON.stringify(data)); - }).catch((error) => { + }).catch((error: BusinessError) => { console.error('install failed:' + error.message); }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -395,23 +403,25 @@ uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallbac ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let bundleName = 'com.ohos.demo'; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1 }; try { - installer.getBundleInstaller().then(data => { - data.uninstall(bundleName, installParam, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.uninstall(bundleName, installParam, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -453,18 +463,20 @@ uninstall(bundleName: string, callback: AsyncCallback<void>): void; ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let bundleName = 'com.ohos.demo'; try { - installer.getBundleInstaller().then(data => { - data.uninstall(bundleName, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.uninstall(bundleName, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -511,22 +523,24 @@ uninstall(bundleName: string, installParam?: InstallParam) : Promise\; **示例:** ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let bundleName = 'com.ohos.demo'; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { - installer.getBundleInstaller().then(data => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.uninstall(bundleName, installParam) - .then((data) => { + .then((data: void) => { console.info('uninstall successfully: ' + JSON.stringify(data)); - }).catch((error) => { + }).catch((error: BusinessError) => { console.error('uninstall failed:' + error.message); }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -567,23 +581,25 @@ recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback& ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let bundleName = 'com.ohos.demo'; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1 }; try { - installer.getBundleInstaller().then(data => { - data.recover(bundleName, installParam, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.recover(bundleName, installParam, (err: BusinessError) => { if (err) { console.error('recover failed:' + err.message); } else { console.info('recover successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -623,18 +639,20 @@ recover(bundleName: string, callback: AsyncCallback<void>): void; ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let bundleName = 'com.ohos.demo'; try { - installer.getBundleInstaller().then(data => { - data.recover(bundleName, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.recover(bundleName, (err: BusinessError) => { if (err) { console.error('recover failed:' + err.message); } else { console.info('recover successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -679,22 +697,24 @@ recover(bundleName: string, installParam?: InstallParam) : Promise\; **示例:** ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let bundleName = 'com.ohos.demo'; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { - installer.getBundleInstaller().then(data => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.recover(bundleName, installParam) - .then((data) => { + .then((data: void) => { console.info('recover successfully: ' + JSON.stringify(data)); - }).catch((error) => { + }).catch((error: BusinessError) => { console.error('recover failed:' + error.message); }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -735,20 +755,22 @@ uninstall(uninstallParam: UninstallParam, callback : AsyncCallback\) : voi ```ts import installer from '@ohos.bundle.installer'; -let uninstallParam = { - bundleName : "com.ohos.demo", +import { BusinessError } from '@ohos.base'; + +let uninstallParam: installer.UninstallParam = { + bundleName: "com.ohos.demo", }; try { - installer.getBundleInstaller().then(data => { - data.uninstall(uninstallParam, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.uninstall(uninstallParam, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -794,20 +816,22 @@ uninstall(uninstallParam: UninstallParam) : Promise\; ```ts import installer from '@ohos.bundle.installer'; -let uninstallParam = { - bundleName : "com.ohos.demo", +import { BusinessError } from '@ohos.base'; + +let uninstallParam: installer.UninstallParam = { + bundleName: "com.ohos.demo", }; try { - installer.getBundleInstaller().then(data => { - data.uninstall(uninstallParam, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.uninstall(uninstallParam, (err: BusinessError) => { if (err) { console.error('uninstall failed:' + err.message); } else { console.info('uninstall successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -864,23 +888,25 @@ updateBundleForSelf(hapFilePaths: Array\, installParam: InstallParam, c ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { - installer.getBundleInstaller().then(data => { - data.updateBundleForSelf(hapFilePaths, installParam, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.updateBundleForSelf(hapFilePaths, installParam, (err: BusinessError) => { if (err) { console.error('updateBundleForSelf failed:' + err.message); } else { console.info('updateBundleForSelf successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -935,18 +961,20 @@ updateBundleForSelf(hapFilePaths: Array\, callback: AsyncCallback\ { - data.updateBundleForSelf(hapFilePaths, err => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { + data.updateBundleForSelf(hapFilePaths, (err: BusinessError) => { if (err) { console.error('updateBundleForSelf failed:' + err.message); } else { console.info('updateBundleForSelf successfully.'); } }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) { @@ -1002,22 +1030,24 @@ updateBundleForSelf(hapFilePaths: Array\, installParam?: InstallParam): ```ts import installer from '@ohos.bundle.installer'; +import { BusinessError } from '@ohos.base'; + let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/']; -let installParam = { +let installParam: installer.InstallParam = { userId: 100, isKeepData: false, installFlag: 1, }; try { - installer.getBundleInstaller().then(data => { + installer.getBundleInstaller().then((data: installer.BundleInstaller) => { data.updateBundleForSelf(hapFilePaths, installParam) - .then((data) => { + .then((data: void) => { console.info('updateBundleForSelf successfully: ' + JSON.stringify(data)); - }).catch((error) => { + }).catch((error: BusinessError) => { console.error('updateBundleForSelf failed:' + error.message); }); - }).catch(error => { + }).catch((error: BusinessError) => { console.error('getBundleInstaller failed. Cause: ' + error.message); }); } catch (error) {