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

告警

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