提交 ac2e654b 编写于 作者: J junyi233

arkts 告警修复

Signed-off-by: Njunyi233 <zhengjun29@huawei.com>
上级 7dbdf0c4
...@@ -136,10 +136,10 @@ struct BasketViewer { ...@@ -136,10 +136,10 @@ struct BasketViewer {
build() { build() {
Column() { Column() {
ForEach(this.shopBasket, ForEach(this.shopBasket,
(item) => { (item:PurchaseItem) => {
Text(`Price: ${item.price.toFixed(2)} €`) Text(`Price: ${item.price.toFixed(2)} €`)
}, },
item => item.id.toString() (item:PurchaseItem) => item.id.toString()
) )
Text(`Total: ${this.totalPurchase.toFixed(2)} €`) Text(`Total: ${this.totalPurchase.toFixed(2)} €`)
} }
......
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
```ts ```ts
import installer from '@ohos.bundle.installer'; import installer from '@ohos.bundle.installer';
import { BusinessError } from '@ohos.base';
let bundleName = 'com.ohos.demo'; let bundleName = 'com.ohos.demo';
let installParam = { let installParam: installer.InstallParam = {
userId: 100 userId: 100
}; };
...@@ -30,11 +31,12 @@ try { ...@@ -30,11 +31,12 @@ try {
console.info('uninstall successfully.'); console.info('uninstall successfully.');
} }
}); });
}).catch(error => { }).catch((error: BusinessError) => {
console.error('getBundleInstaller failed. Cause: ' + error.message); console.error('getBundleInstaller failed. Cause: ' + error.message);
}); });
} catch (error) { } catch (error) {
console.error('getBundleInstaller failed. Cause: ' + error.message); let message = (error as BusinessError).message;
console.error('getBundleInstaller failed. Cause: ' + message);
} }
``` ```
......
...@@ -165,6 +165,7 @@ preloads列表配置的moduleName对应的[moduleType(模块类型)](../referenc ...@@ -165,6 +165,7 @@ preloads列表配置的moduleName对应的[moduleType(模块类型)](../referenc
```ts ```ts
import router from '@ohos.router'; import router from '@ohos.router';
import { BusinessError } from '@ohos.base';
@Entry @Entry
@Component @Component
...@@ -196,7 +197,7 @@ struct Index { ...@@ -196,7 +197,7 @@ struct Index {
url: '@bundle:com.example.hmservice/library/ets/pages/menu' url: '@bundle:com.example.hmservice/library/ets/pages/menu'
}).then(() => { }).then(() => {
console.log("push page success"); console.log("push page success");
}).catch(err => { }).catch((err: BusinessError) => {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
}) })
}) })
......
...@@ -82,7 +82,8 @@ export function foo2() { ...@@ -82,7 +82,8 @@ export function foo2() {
import native from "libnative.so" import native from "libnative.so"
export function nativeMulti(a: number, b: number) { export function nativeMulti(a: number, b: number) {
return native.multi(a, b); let result: number = native.multi(a, b);
return result;
} }
``` ```
......
...@@ -23,7 +23,7 @@ library ...@@ -23,7 +23,7 @@ library
```ts ```ts
// library/src/main/ets/utils/test.ts // library/src/main/ets/utils/test.ts
export class Log { export class Log {
static info(msg) { static info(msg: string) {
console.info(msg); console.info(msg);
} }
} }
...@@ -119,7 +119,8 @@ export { ResManager } from './ResManager' ...@@ -119,7 +119,8 @@ export { ResManager } from './ResManager'
import native from "libnative.so" import native from "libnative.so"
export function nativeMulti(a: number, b: number) { export function nativeMulti(a: number, b: number) {
return native.multi(a, b); let result: number = native.multi(a, b);
return result;
} }
``` ```
...@@ -194,6 +195,7 @@ struct Index { ...@@ -194,6 +195,7 @@ struct Index {
若开发者想在entry模块中,添加一个按钮跳转至library模块中的menu页面(路径为:`library/src/main/ets/pages/menu.ets`),那么可以在使用方的代码(entry模块下的Index.ets,路径为:`entry/src/main/ets/MainAbility/Index.ets`)里这样使用: 若开发者想在entry模块中,添加一个按钮跳转至library模块中的menu页面(路径为:`library/src/main/ets/pages/menu.ets`),那么可以在使用方的代码(entry模块下的Index.ets,路径为:`entry/src/main/ets/MainAbility/Index.ets`)里这样使用:
```ts ```ts
import router from '@ohos.router'; import router from '@ohos.router';
import { BusinessError } from '@ohos.base';
@Entry @Entry
@Component @Component
...@@ -225,7 +227,7 @@ struct Index { ...@@ -225,7 +227,7 @@ struct Index {
url: '@bundle:com.example.hmservice/library/ets/pages/menu' url: '@bundle:com.example.hmservice/library/ets/pages/menu'
}).then(() => { }).then(() => {
console.log("push page success"); console.log("push page success");
}).catch(err => { }).catch((err: BusinessError) => {
console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`);
}) })
}) })
......
...@@ -1020,9 +1020,10 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: numbe ...@@ -1020,9 +1020,10 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: numbe
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1078,8 +1079,9 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: Asy ...@@ -1078,8 +1079,9 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: Asy
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1142,9 +1144,10 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: numb ...@@ -1142,9 +1144,10 @@ queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: numb
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1165,8 +1168,9 @@ try { ...@@ -1165,8 +1168,9 @@ try {
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1227,9 +1231,10 @@ queryAbilityInfoSync(want: Want, abilityFlags: [number](#abilityflag), userId?: ...@@ -1227,9 +1231,10 @@ queryAbilityInfoSync(want: Want, abilityFlags: [number](#abilityflag), userId?:
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1248,8 +1253,9 @@ try { ...@@ -1248,8 +1253,9 @@ try {
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1302,10 +1308,11 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp ...@@ -1302,10 +1308,11 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1361,9 +1368,10 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp ...@@ -1361,9 +1368,10 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1426,11 +1434,12 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp ...@@ -1426,11 +1434,12 @@ queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityTyp
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1451,9 +1460,10 @@ try { ...@@ -1451,9 +1460,10 @@ try {
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1514,11 +1524,12 @@ queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: [ExtensionAbilit ...@@ -1514,11 +1524,12 @@ queryExtensionAbilityInfoSync(want: Want, extensionAbilityType: [ExtensionAbilit
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -1536,9 +1547,10 @@ try { ...@@ -1536,9 +1547,10 @@ try {
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM; let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT; let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
...@@ -2140,18 +2152,18 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE ...@@ -2140,18 +2152,18 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
let info;
try { try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0]; let info = abilitiesInfo[0];
bundleManager.setAbilityEnabled(info, false, err => { bundleManager.setAbilityEnabled(info, false, err => {
if (err) { if (err) {
...@@ -2209,18 +2221,18 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE ...@@ -2209,18 +2221,18 @@ setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isE
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
let info;
try { try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0]; let info = abilitiesInfo[0];
bundleManager.setAbilityEnabled(info, false).then(() => { bundleManager.setAbilityEnabled(info, false).then(() => {
hilog.info(0x0000, "testTag", "setAbilityEnabled successfully."); hilog.info(0x0000, "testTag", "setAbilityEnabled successfully.");
...@@ -2270,26 +2282,27 @@ setAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), ...@@ -2270,26 +2282,27 @@ setAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md),
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
let info;
try { try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0]; let info = abilitiesInfo[0];
try { try {
bundleManager.setAbilityEnabledSync(info, false); bundleManager.setAbilityEnabledSync(info, false);
hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully."); hilog.info(0x0000, "testTag", "setAbilityEnabledSync successfully.");
} catch (err) { } catch (err) {
hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', err.message); let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'setAbilityEnabledSync failed: %{public}s', message);
} }
}).catch(err => { }).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
}); });
} catch (err) { } catch (err) {
...@@ -2474,18 +2487,18 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), call ...@@ -2474,18 +2487,18 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), call
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
let info;
try { try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0]; let info = abilitiesInfo[0];
bundleManager.isAbilityEnabled(info, (err, data) => { bundleManager.isAbilityEnabled(info, (err, data) => {
if (err) { if (err) {
...@@ -2540,25 +2553,25 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Pro ...@@ -2540,25 +2553,25 @@ isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Pro
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
let info;
try { try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0]; let info = abilitiesInfo[0];
bundleManager.isAbilityEnabled(info).then((data) => { bundleManager.isAbilityEnabled(info).then((data) => {
hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data)); hilog.info(0x0000, 'testTag', 'isAbilityEnabled successfully. Data: %{public}s', JSON.stringify(data));
}).catch(err => { }).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message); hilog.error(0x0000, 'testTag', 'isAbilityEnabled failed. Cause: %{public}s', err.message);
}); });
}).catch(err => { }).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
}); });
} catch (err) { } catch (err) {
...@@ -2604,26 +2617,27 @@ isAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): ...@@ -2604,26 +2617,27 @@ isAbilityEnabledSync(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)):
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT; let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100; let userId = 100;
let want = { let want: Want = {
bundleName : "com.example.myapplication", bundleName : "com.example.myapplication",
abilityName : "EntryAbility" abilityName : "EntryAbility"
}; };
let info;
try { try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => { bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo)); hilog.info(0x0000, 'testTag', 'queryAbilityInfo successfully. Data: %{public}s', JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0]; let info = abilitiesInfo[0];
try { try {
let data = bundleManager.isAbilityEnabledSync(info); let data = bundleManager.isAbilityEnabledSync(info);
hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data)); hilog.info(0x0000, 'testTag', 'isAbilityEnabledSync successfully: %{public}s', JSON.stringify(data));
} catch (err) { } catch (err) {
hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', err.message); let message = (err as BusinessError).message;
hilog.error(0x0000, 'testTag', 'isAbilityEnabledSync failed: %{public}s', message);
} }
}).catch(err => { }).catch((err: BusinessError) => {
hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message); hilog.error(0x0000, 'testTag', 'queryAbilityInfo failed. Cause: %{public}s', err.message);
}); });
} catch (err) { } catch (err) {
...@@ -2833,11 +2847,12 @@ getLaunchWantForBundleSync(bundleName: string, userId?: number): Want; ...@@ -2833,11 +2847,12 @@ getLaunchWantForBundleSync(bundleName: string, userId?: number): Want;
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let bundleName = 'com.example.myapplication'; let bundleName = 'com.example.myapplication';
let userId = 100; let userId = 100;
try { try {
let want = bundleManager.getLaunchWantForBundleSync(bundleName, userId); let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName, userId);
hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want));
} catch (err) { } catch (err) {
let message = (err as BusinessError).message; let message = (err as BusinessError).message;
...@@ -2849,11 +2864,12 @@ try { ...@@ -2849,11 +2864,12 @@ try {
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
import hilog from '@ohos.hilog'; import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
let bundleName = 'com.example.myapplication'; let bundleName = 'com.example.myapplication';
let userId = 100; let userId = 100;
try { try {
let want = bundleManager.getLaunchWantForBundleSync(bundleName); let want: Want = bundleManager.getLaunchWantForBundleSync(bundleName);
hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want)); hilog.info(0x0000, 'testTag', 'getLaunchWantForBundleSync successfully. Data: %{public}s', JSON.stringify(want));
} catch (err) { } catch (err) {
let message = (err as BusinessError).message; let message = (err as BusinessError).message;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册