未验证 提交 2ef8d068 编写于 作者: O openharmony_ci 提交者: Gitee

!13769 WorkSchedulerExtensionAbility开发指南修改

Merge pull request !13769 from 朱天怡/master
......@@ -9,7 +9,7 @@ ExtensionAbility组件是基于特定场景(例如服务卡片、输入法等
- [FormExtensionAbility](../reference/apis/js-apis-app-form-formExtensionAbility.md):FORM类型的ExtensionAbility组件,用于提供服务卡片场景相关能力。
- [WorkSchedulerExtensionAbility](../reference/apis/js-apis-resourceschedule-workScheduler.md):WORK_SCHEDULER类型的ExtensionAbility组件,用于提供延迟任务注册、取消、查询的能力。
- [WorkSchedulerExtensionAbility](../reference/apis/js-apis-resourceschedule-workScheduler.md):WORK_SCHEDULER类型的ExtensionAbility组件,用于提供延迟任务回调实现的能力。
- [InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod.md):INPUT_METHOD类型的ExtensionAbility组件,提供对输入法框架的管理,包括隐藏输入法、查询已安装的输入法列表和显示输入法选择对话框。
......
......@@ -43,7 +43,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
```
实现WorkSchedulerExtension生命周期接口。
......@@ -52,27 +52,27 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
export default class workAbility extends WorkSchedulerExtensionAbility {
// 延迟任务开始回调
onWorkStart(workInfo) {
console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`)
console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`);
// 发送升级通知
let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, '')
let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, '');
notification.publish(notificationRequest, (err) => {
if (err) {
console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`)
console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`);
}
console.log(`onWorkStart notification publish success`)
})
console.log(`onWorkStart notification publish success`);
});
}
// 延迟任务结束回调
onWorkStop(workInfo) {
// 发送升级完成通知
let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', '')
let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', '');
notification.publish(notificationRequest, (err) => {
if (err) {
console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`)
console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`);
}
console.log(`onWorkStop notification publish success`)
})
console.log(`onWorkStop notification publish success`);
});
}
}
```
......@@ -91,13 +91,13 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
```ts
export default class WorkTest extends workAbility {
onWorkStart(workInfo) {
console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`)
super.onWorkStart(workInfo)
console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`);
super.onWorkStart(workInfo);
}
onWorkStopTest(workInfo) {
super.onWorkStop(workInfo)
console.log(`onWorkStop value`)
super.onWorkStop(workInfo);
console.log(`onWorkStop value`);
}
}
```
......@@ -109,7 +109,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import workScheduler from '@ohos.resourceschedule.workScheduler'
import workScheduler from '@ohos.resourceschedule.workScheduler';
```
封装延迟任务注册、停止接口。
......@@ -124,25 +124,25 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
}
// 注册延迟任务
startWork(bundleName: string, abilityName: string) {
this.workInfo.bundleName = bundleName
this.workInfo.abilityName = abilityName
this.workInfo.bundleName = bundleName;
this.workInfo.abilityName = abilityName;
try {
workScheduler.startWork(this.workInfo)
console.log(`startWork success`)
workScheduler.startWork(this.workInfo);
console.log(`startWork success`);
} catch (error) {
Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`)
Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`);
prompt.showToast({
message: `${error.message}`
})
});
}
}
// 停止延迟任务
stopWork(bundleName: string, abilityName: string) {
this.workInfo.bundleName = bundleName
this.workInfo.abilityName = abilityName
workScheduler.stopWork(this.workInfo, false)
console.log(`stopWork`)
this.workInfo.bundleName = bundleName;
this.workInfo.abilityName = abilityName;
workScheduler.stopWork(this.workInfo, false);
console.log(`stopWork`);
}
}
```
......@@ -152,7 +152,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import { workAbility } from '@ohos/library'
import { workAbility } from '@ohos/library';
```
增加“升级”按钮,调用library封装的延迟任务注册接口,传入bundleName和abilityName,其中bilityName为WorkTest。
......@@ -163,15 +163,15 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
.height(40)
.fontSize(30)
.onClick(() => {
this.work.startWork('ohos.samples.workscheduler', 'WorkTest')
})
this.work.startWork('ohos.samples.workscheduler', 'WorkTest');
});
```
在组件析构时,调用延迟任务停止接口。
```ts
aboutToDisappear() {
this.work.stopWork('ohos.samples.workscheduler', 'WorkTest')
this.work.stopWork('ohos.samples.workscheduler', 'WorkTest');
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册