提交 bb125569 编写于 作者: G Gloria

Update docs against 16863

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 c7900e92
...@@ -57,17 +57,18 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -57,17 +57,18 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
```js ```js
import workScheduler from '@ohos.resourceschedule.workScheduler'; import workScheduler from '@ohos.resourceschedule.workScheduler';
``` ```
Import the **WorkSchedulerExtensionAbility** module. Import the **WorkSchedulerExtensionAbility** module.
```js ```js
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
``` ```
2. Develop an ExtensionAbility to execute a Work Scheduler task. For details about the ExtensionAbility, see [ExtensionAbility Component Overview](../application-models/extensionability-overview.md) and [WorkSchedulerExtensionAbility Development](./workscheduler-extensionability.md). 2. Develop an ExtensionAbility to execute a Work Scheduler task. For details about the ExtensionAbility, see [ExtensionAbility Component Overview](../application-models/extensionability-overview.md) and [WorkSchedulerExtensionAbility Development](./workscheduler-extensionability.md).
```ts ```ts
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
export default class MyExtension extends WorkSchedulerExtensionAbility { export default class MyExtension extends WorkSchedulerExtensionAbility {
onWorkStart(workInfo) { onWorkStart(workInfo) {
console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo)); console.log('MyWorkSchedulerExtensionAbility onWorkStart' + JSON.stringify(workInfo));
...@@ -78,12 +79,11 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -78,12 +79,11 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
} }
``` ```
3. Start a Work Scheduler task. 3. Start a Work Scheduler task.
```ts ```ts
import workScheduler from '@ohos.resourceschedule.workScheduler'; import workScheduler from '@ohos.resourceschedule.workScheduler';
let workInfo = { let workInfo = {
workId: 1, workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
...@@ -102,16 +102,15 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -102,16 +102,15 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
workScheduler.startWork(workInfo); workScheduler.startWork(workInfo);
console.info('workschedulerLog startWork success'); console.info('workschedulerLog startWork success');
} catch (error) { } catch (error) {
console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
4. Stop the Work Scheduler task. 4. Stop the Work Scheduler task.
```ts ```ts
import workScheduler from '@ohos.resourceschedule.workScheduler'; import workScheduler from '@ohos.resourceschedule.workScheduler';
let workInfo = { let workInfo = {
workId: 1, workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
...@@ -124,33 +123,31 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -124,33 +123,31 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
mykey1: "string value", mykey1: "string value",
mykey2: true, mykey2: true,
mykey3: 1.5 mykey3: 1.5
} }
} }
try{ try{
workScheduler.stopWork(workInfo, false); workScheduler.stopWork(workInfo, false);
console.info('workschedulerLog stopWork success'); console.info('workschedulerLog stopWork success');
} catch (error) { } catch (error) {
console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
5. Obtain a specified Work Scheduler task. 5. Obtain a specified Work Scheduler task.
```ts ```ts
try{ try{
workScheduler.getWorkStatus(50, (error, res) => { workScheduler.getWorkStatus(50, (error, res) => {
if (error) { if (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
} else { } else {
for (let item in res) { for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
} }
} }
}); });
} catch (error) { } catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
...@@ -160,13 +157,13 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -160,13 +157,13 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
try{ try{
workScheduler.obtainAllWorks((error, res) =>{ workScheduler.obtainAllWorks((error, res) =>{
if (error) { if (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
} else { } else {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
} }
}); });
} catch (error) { } catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
...@@ -177,7 +174,7 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -177,7 +174,7 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
workScheduler.stopAndClearWorks(); workScheduler.stopAndClearWorks();
console.info(`workschedulerLog stopAndClearWorks success`); console.info(`workschedulerLog stopAndClearWorks success`);
} catch (error) { } catch (error) {
console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
...@@ -187,7 +184,7 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -187,7 +184,7 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
try{ try{
workScheduler.isLastWorkTimeOut(500, (error, res) =>{ workScheduler.isLastWorkTimeOut(500, (error, res) =>{
if (error) { if (error) {
onsole.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
} else { } else {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
} }
...@@ -195,4 +192,4 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops. ...@@ -195,4 +192,4 @@ onWorkStop(work: WorkInfo): void | Called when the Work Scheduler task stops.
} catch (error) { } catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
} }
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册