未验证 提交 48a70a63 编写于 作者: 朱天怡 提交者: Gitee

告警修复

Signed-off-by: N朱天怡 <zhutianyi2@huawei.com>
上级 69c7d53f
...@@ -83,6 +83,7 @@ ...@@ -83,6 +83,7 @@
```ts ```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent'; import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
import { BusinessError } from '@ohos.base';
``` ```
4. 申请和取消长时任务。 4. 申请和取消长时任务。
...@@ -188,13 +189,14 @@ ...@@ -188,13 +189,14 @@
import window from '@ohos.window'; import window from '@ohos.window';
import AbilityConstant from '@ohos.app.ability.AbilityConstant'; import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want'; import Want from '@ohos.app.ability.Want';
import rpc from '@ohos.rpc';
const MSG_SEND_METHOD: string = 'CallSendMsg' const MSG_SEND_METHOD: string = 'CallSendMsg'
let mContext = null; let mContext: Context;
function startContinuousTask() { function startContinuousTask() {
let wantAgentInfo = { let wantAgentInfo : wantAgent.WantAgentInfo = {
// 点击通知后,将要执行的动作列表 // 点击通知后,将要执行的动作列表
wants: [ wants: [
{ {
...@@ -211,62 +213,54 @@ ...@@ -211,62 +213,54 @@
}; };
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象 // 通过wantAgent模块的getWantAgent方法获取WantAgent对象
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj : WantAgent) => {
try {
backgroundTaskManager.startBackgroundRunning(mContext, backgroundTaskManager.startBackgroundRunning(mContext,
backgroundTaskManager.BackgroundMode.AUDIO_RECORDING, wantAgentObj).then(() => { backgroundTaskManager.BackgroundMode.AUDIO_RECORDING, wantAgentObj).then(() => {
console.info(`Succeeded in operationing startBackgroundRunning.`); console.info(`Succeeded in operationing startBackgroundRunning.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to operation startBackgroundRunning. Code is ${err.code}, message is ${err.message}`); console.error(`Failed to operation startBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}); });
} catch (err) {
console.error(`Failed to operation startBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}
}); });
} }
function stopContinuousTask() { function stopContinuousTask() {
try {
backgroundTaskManager.stopBackgroundRunning(mContext).then(() => { backgroundTaskManager.stopBackgroundRunning(mContext).then(() => {
console.info(`Succeeded in operationing stopBackgroundRunning.`); console.info(`Succeeded in operationing stopBackgroundRunning.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`); console.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}); });
} catch (err) {
console.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}
} }
class MyParcelable { class MyParcelable {
num: number = 0; num: number = 0;
str: String = ''; str: String = '';
constructor(num, string) { constructor(num: number, string: string) {
this.num = num; this.num = num;
this.str = string; this.str = string;
} }
marshalling(messageSequence) { marshalling(messageSequence: rpc.MessageSequence) {
messageSequence.writeInt(this.num); messageSequence.writeInt(this.num);
messageSequence.writeString(this.str); messageSequence.writeString(this.str);
return true; return true;
} }
unmarshalling(messageSequence) { unmarshalling(messageSequence: rpc.MessageSequence) {
this.num = messageSequence.readInt(); this.num = messageSequence.readInt();
this.str = messageSequence.readString(); this.str = messageSequence.readString();
return true; return true;
} }
} }
function sendMsgCallback(data) { function sendMsgCallback(data: rpc.MessageSequence) {
console.info('BgTaskAbility funcCallBack is called ' + data) console.info('BgTaskAbility funcCallBack is called ' + data);
let receivedData = new MyParcelable(0, '') let receivedData = new MyParcelable(0, '');
data.readParcelable(receivedData) data.readParcelable(receivedData);
console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`) console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`);
// 可以根据Caller端发送的序列化数据的str值,执行不同的方法。 // 可以根据Caller端发送的序列化数据的str值,执行不同的方法。
if (receivedData.str === 'start_bgtask') { if (receivedData.str === 'start_bgtask') {
startContinuousTask() startContinuousTask();
} else if (receivedData.str === 'stop_bgtask') { } else if (receivedData.str === 'stop_bgtask') {
stopContinuousTask(); stopContinuousTask();
} }
...@@ -274,42 +268,44 @@ ...@@ -274,42 +268,44 @@
} }
export default class BgTaskAbility extends UIAbility { export default class BgTaskAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
console.info("[Demo] BgTaskAbility onCreate") console.info("[Demo] BgTaskAbility onCreate");
this.callee.on('test', sendMsgCallback); this.callee.on('test', sendMsgCallback);
try { try {
this.callee.on(MSG_SEND_METHOD, sendMsgCallback) this.callee.on(MSG_SEND_METHOD, sendMsgCallback)
} catch (error) { } catch (error) {
console.error(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`) console.error(`${MSG_SEND_METHOD} register failed with error ${JSON.stringify(error)}`);
} }
mContext = this.context; mContext = this.context;
} }
onDestroy() { onDestroy() {
console.info('[Demo] BgTaskAbility onDestroy') console.info('[Demo] BgTaskAbility onDestroy');
} }
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage: window.WindowStage) {
console.info('[Demo] BgTaskAbility onWindowStageCreate') console.info('[Demo] BgTaskAbility onWindowStageCreate');
windowStage.loadContent("pages/index").then((data) => { windowStage.loadContent('pages/Index', (error, data) => {
console.info(`load content succeed with data ${JSON.stringify(data)}`) if (error.code) {
}).catch((error) => { console.error(`load content failed with error ${JSON.stringify(error)}`);
console.error(`load content failed with error ${JSON.stringify(error)}`) return;
}) }
console.info(`load content succeed with data ${JSON.stringify(data)}`);
});
} }
onWindowStageDestroy() { onWindowStageDestroy() {
console.info('[Demo] BgTaskAbility onWindowStageDestroy') console.info('[Demo] BgTaskAbility onWindowStageDestroy');
} }
onForeground() { onForeground() {
console.info('[Demo] BgTaskAbility onForeground') console.info('[Demo] BgTaskAbility onForeground');
} }
onBackground() { onBackground() {
console.info('[Demo] BgTaskAbility onBackground') console.info('[Demo] BgTaskAbility onBackground');
} }
}; };
``` ```
...@@ -352,15 +348,16 @@ ...@@ -352,15 +348,16 @@
```js ```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
import rpc from "@ohos.rpc"; import rpc from "@ohos.rpc";
import { BusinessError } from '@ohos.base';
``` ```
4. 申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消。 4. 申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消。
```js ```js
function startContinuousTask() { function startContinuousTask() {
let wantAgentInfo = { let wantAgentInfo: wantAgent.WantAgentInfo = {
// 点击通知后,将要执行的动作列表 // 点击通知后,将要执行的动作列表
wants: [ wants: [
{ {
...@@ -377,30 +374,22 @@ ...@@ -377,30 +374,22 @@
}; };
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象 // 通过wantAgent模块的getWantAgent方法获取WantAgent对象
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
try {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.AUDIO_RECORDING, wantAgentObj).then(() => { backgroundTaskManager.BackgroundMode.AUDIO_RECORDING, wantAgentObj).then(() => {
console.info(`Succeeded in operationing startBackgroundRunning.`); console.info(`Succeeded in operationing startBackgroundRunning.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to operation startBackgroundRunning. Code is ${err.code}, message is ${err.message}`); console.error(`Failed to operation startBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}); });
} catch (error) {
console.error(`Failed to operation startBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}
}); });
} }
function stopContinuousTask() { function stopContinuousTask() {
try {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info(`Succeeded in operationing stopBackgroundRunning.`); console.info(`Succeeded in operationing stopBackgroundRunning.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`); console.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}); });
} catch (error) {
console.error(`Failed to operation stopBackgroundRunning. Code is ${err.code}, message is ${err.message}`);
}
} }
async function processAsyncJobs() { async function processAsyncJobs() {
...@@ -410,7 +399,7 @@ ...@@ -410,7 +399,7 @@
stopContinuousTask(); stopContinuousTask();
} }
let mMyStub; let mMyStub: MyStub;
class MyStub extends rpc.RemoteObject { class MyStub extends rpc.RemoteObject {
constructor(des) { constructor(des) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册