未验证 提交 69c7d53f 编写于 作者: 朱天怡 提交者: Gitee

告警

Signed-off-by: N朱天怡 <zhutianyi2@huawei.com>
上级 db741516
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
```ts ```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
``` ```
4. 申请和取消长时任务。 4. 申请和取消长时任务。
...@@ -99,10 +99,10 @@ ...@@ -99,10 +99,10 @@
struct Index { struct Index {
@State message: string = 'ContinuousTask'; @State message: string = 'ContinuousTask';
// 通过getContext方法,来获取page所在的UIAbility上下文。 // 通过getContext方法,来获取page所在的UIAbility上下文。
private context = getContext(this); private context: Context = getContext(this);
startContinuousTask() { startContinuousTask() {
let wantAgentInfo = { let wantAgentInfo: wantAgent.wantAgentInfo = {
// 点击通知后,将要执行的动作列表 // 点击通知后,将要执行的动作列表
wants: [ wants: [
{ {
...@@ -119,30 +119,22 @@ ...@@ -119,30 +119,22 @@
}; };
// 通过wantAgent模块下getWantAgent方法获取WantAgent对象 // 通过wantAgent模块下getWantAgent方法获取WantAgent对象
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
try { backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.startBackgroundRunning(this.context, 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: BusinessError) => {
}).catch((err) => { 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 start background running. Code is ${error.code} message is ${error.message}`);
}
}); });
} }
stopContinuousTask() { stopContinuousTask() {
try { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { console.info(`Succeeded in operationing stopBackgroundRunning.`);
console.info(`Succeeded in operationing stopBackgroundRunning.`); }).catch((err: BusinessError) => {
}).catch((err) => { 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 stop background running. Code is ${error.code} message is ${error.message}`);
}
} }
build() { build() {
...@@ -193,6 +185,9 @@ ...@@ -193,6 +185,9 @@
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
const MSG_SEND_METHOD: string = 'CallSendMsg' const MSG_SEND_METHOD: string = 'CallSendMsg'
......
...@@ -121,6 +121,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -121,6 +121,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
```ts ```ts
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
import workScheduler fron '@ohos.resourceschedule.workScheduler';
``` ```
3. 实现WorkSchedulerExtension生命周期接口。 3. 实现WorkSchedulerExtension生命周期接口。
...@@ -128,12 +129,12 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -128,12 +129,12 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
```ts ```ts
export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility { export default class MyWorkSchedulerExtensionAbility extends WorkSchedulerExtensionAbility {
// 延迟任务开始回调 // 延迟任务开始回调
onWorkStart(workInfo) { onWorkStart(workInfo: workScheduler.WorkInfo) {
console.info(`onWorkStart, workInfo = ${JSON.stringify(workInfo)}`); console.info(`onWorkStart, workInfo = ${JSON.stringify(workInfo)}`);
} }
// 延迟任务结束回调 // 延迟任务结束回调
onWorkStop(workInfo) { onWorkStop(workInfo: workScheduler.WorkInfo) {
console.info(`onWorkStop, workInfo is ${JSON.stringify(workInfo)}`); console.info(`onWorkStop, workInfo is ${JSON.stringify(workInfo)}`);
} }
} }
...@@ -173,7 +174,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -173,7 +174,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
2. 申请延迟任务。 2. 申请延迟任务。
```ts ```ts
private workInfo = { private workInfo: workScheduler.WorkInfo = {
workId: 1, workId: 1,
networkType: workScheduler.NetworkType.NETWORK_TYPE_WIFI, networkType: workScheduler.NetworkType.NETWORK_TYPE_WIFI,
bundleName: 'com.example.application', bundleName: 'com.example.application',
...@@ -183,7 +184,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -183,7 +184,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try { try {
workScheduler.startWork(this.workInfo); workScheduler.startWork(this.workInfo);
console.info(`startWork success`); console.info(`startWork success`);
} catch (error) { } catch (error: BusinessError) {
console.error(`startWork failed. code is ${error.code} message is ${error.message}`); console.error(`startWork failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
...@@ -191,7 +192,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -191,7 +192,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
3. 取消延迟任务。 3. 取消延迟任务。
```ts ```ts
private workInfo = { private workInfo: workScheduler.workInfo = {
workId: 1, workId: 1,
networkType: workScheduler.NetworkType.NETWORK_TYPE_WIFI, networkType: workScheduler.NetworkType.NETWORK_TYPE_WIFI,
bundleName: 'com.example.application', bundleName: 'com.example.application',
...@@ -201,7 +202,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -201,7 +202,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try { try {
workScheduler.stopWork(this.workInfo); workScheduler.stopWork(this.workInfo);
console.info(`stopWork success`); console.info(`stopWork success`);
} catch (error) { } catch (error: BusinessError) {
console.error(`stopWork failed. code is ${error.code} message is ${error.message}`); console.error(`stopWork failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册