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

告警修复

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