未验证 提交 756132ba 编写于 作者: O openharmony_ci 提交者: Gitee

!23802 arkts告警修复

Merge pull request !23802 from 朱天怡/master
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
## 导入模块 ## 导入模块
```js ```ts
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
``` ```
...@@ -47,7 +47,7 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen ...@@ -47,7 +47,7 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen
**示例** **示例**
```js ```ts
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
let myReason = 'test requestSuspendDelay'; let myReason = 'test requestSuspendDelay';
...@@ -79,11 +79,11 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): ...@@ -79,11 +79,11 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>):
**示例** **示例**
```js ```ts
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {}); let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {});
backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId, (err, res) => { backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId, (err: BusinessError, res: number) => {
if(err) { if(err) {
console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.code); console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.code);
} else { } else {
...@@ -115,7 +115,7 @@ getRemainingDelayTime(requestId: number): Promise<number> ...@@ -115,7 +115,7 @@ getRemainingDelayTime(requestId: number): Promise<number>
**示例** **示例**
```js ```ts
let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {}); let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {});
backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId).then((res:number) => { backgroundTaskManager.getRemainingDelayTime(delayInfo.requestId).then((res:number) => {
console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
...@@ -141,7 +141,7 @@ cancelSuspendDelay(requestId: number): void ...@@ -141,7 +141,7 @@ cancelSuspendDelay(requestId: number): void
**示例** **示例**
```js ```ts
let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {}); let delayInfo = backgroundTaskManager.requestSuspendDelay("test", () => {});
backgroundTaskManager.cancelSuspendDelay(delayInfo.requestId); backgroundTaskManager.cancelSuspendDelay(delayInfo.requestId);
``` ```
...@@ -267,7 +267,7 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want ...@@ -267,7 +267,7 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
**示例** **示例**
FA模型示例: FA模型示例(需使用js代码开发)
```js ```js
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
...@@ -348,7 +348,7 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): vo ...@@ -348,7 +348,7 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): vo
**示例** **示例**
FA模型示例: FA模型示例(需使用js代码开发)
```js ```js
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
## 导入模块 ## 导入模块
```js ```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
``` ```
...@@ -53,22 +53,23 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen ...@@ -53,22 +53,23 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen
**示例** **示例**
```js ```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let myReason = 'test requestSuspendDelay'; let myReason = 'test requestSuspendDelay';
try { try {
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspension delay will time out."); console.info("Request suspension delay will time out.");
}) })
let id = delayInfo.requestId; let id = delayInfo.requestId;
let time = delayInfo.actualDelayTime; let time = delayInfo.actualDelayTime;
console.info("The requestId is: " + id); console.info("The requestId is: " + id);
console.info("The actualDelayTime is: " + time); console.info("The actualDelayTime is: " + time);
} catch (error) { } catch (error) {
console.error(`requestSuspendDelay failed. code is ${error.code} message is ${error.message}`); console.error(`requestSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
## backgroundTaskManager.getRemainingDelayTime ## backgroundTaskManager.getRemainingDelayTime
...@@ -102,22 +103,19 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): ...@@ -102,22 +103,19 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>):
**示例** **示例**
```js ```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let id = 1; let id = 1;
try { backgroundTaskManager.getRemainingDelayTime(id, (error: BusinessError, res: number) => {
backgroundTaskManager.getRemainingDelayTime(id, (error, res) => {
if(error) { if(error) {
console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`); console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
} else { } else {
console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
} }
}) })
} catch (error) { ```
console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
}
```
## backgroundTaskManager.getRemainingDelayTime ## backgroundTaskManager.getRemainingDelayTime
...@@ -155,20 +153,17 @@ getRemainingDelayTime(requestId: number): Promise<number> ...@@ -155,20 +153,17 @@ getRemainingDelayTime(requestId: number): Promise<number>
**示例** **示例**
```js ```ts
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let id = 1; let id = 1;
try { backgroundTaskManager.getRemainingDelayTime(id).then((res: number) => {
backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res)); console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
}).catch( error => { }).catch((error: BusinessError) => {
console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`); console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
}) })
} catch (error) { ```
console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
}
```
## backgroundTaskManager.cancelSuspendDelay ## backgroundTaskManager.cancelSuspendDelay
...@@ -202,12 +197,13 @@ cancelSuspendDelay(requestId: number): void ...@@ -202,12 +197,13 @@ cancelSuspendDelay(requestId: number): void
```js ```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let id = 1; let id = 1;
try { try {
backgroundTaskManager.cancelSuspendDelay(id); backgroundTaskManager.cancelSuspendDelay(id);
} catch (error) { } catch (error) {
console.error(`cancelSuspendDelay failed. code is ${error.code} message is ${error.message}`); console.error(`cancelSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
...@@ -249,9 +245,10 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want ...@@ -249,9 +245,10 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
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';
import { BusinessError } from '@ohos.base';
function callback(error, data) { function callback(error: BusinessError, data: void) {
if (error) { if (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
} else { } else {
...@@ -260,8 +257,8 @@ function callback(error, data) { ...@@ -260,8 +257,8 @@ function callback(error, data) {
} }
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
let wantAgentInfo = { let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -274,16 +271,16 @@ export default class EntryAbility extends UIAbility { ...@@ -274,16 +271,16 @@ export default class EntryAbility extends UIAbility {
}; };
try { try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
try { try {
backgroundTaskManager.startBackgroundRunning(this.context, backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback) backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
} catch (error) { } catch (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
}); });
} catch (error) { } catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`); console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
} }
}; };
...@@ -332,11 +329,12 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want ...@@ -332,11 +329,12 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
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';
import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
let wantAgentInfo = { let wantAgentInfo: wantAgent.WantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
...@@ -349,20 +347,20 @@ export default class EntryAbility extends UIAbility { ...@@ -349,20 +347,20 @@ export default class EntryAbility extends UIAbility {
}; };
try { try {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
try { try {
backgroundTaskManager.startBackgroundRunning(this.context, backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => { backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => {
console.info("Operation startBackgroundRunning succeeded"); console.info("Operation startBackgroundRunning succeeded");
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}); });
} catch (error) { } catch (error) {
console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
}); });
} catch (error) { } catch (error) {
console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`); console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
} }
}; };
...@@ -402,8 +400,9 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): vo ...@@ -402,8 +400,9 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback<void>): vo
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
function callback(error, data) { function callback(error: BusinessError, data: void) {
if (error) { if (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
} else { } else {
...@@ -412,11 +411,11 @@ function callback(error, data) { ...@@ -412,11 +411,11 @@ function callback(error, data) {
} }
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try { try {
backgroundTaskManager.stopBackgroundRunning(this.context, callback); backgroundTaskManager.stopBackgroundRunning(this.context, callback);
} catch (error) { } catch (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
} }
}; };
...@@ -461,17 +460,18 @@ stopBackgroundRunning(context: Context): Promise<void> ...@@ -461,17 +460,18 @@ stopBackgroundRunning(context: Context): Promise<void>
```js ```js
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try { try {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
console.info("Operation stopBackgroundRunning succeeded"); console.info("Operation stopBackgroundRunning succeeded");
}).catch((error) => { }).catch((error: BusinessError) => {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}); });
} catch (error) { } catch (error) {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
} }
}; };
...@@ -510,8 +510,9 @@ applyEfficiencyResources(request: EfficiencyResourcesRequest): void ...@@ -510,8 +510,9 @@ applyEfficiencyResources(request: EfficiencyResourcesRequest): void
```js ```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import { BusinessError } from '@ohos.base';
let request = { let request: backgroundTaskManager.EfficiencyResourcesRequest = {
resourceTypes: backgroundTaskManager.ResourceType.CPU, resourceTypes: backgroundTaskManager.ResourceType.CPU,
isApply: true, isApply: true,
timeOut: 0, timeOut: 0,
...@@ -523,7 +524,7 @@ try { ...@@ -523,7 +524,7 @@ try {
backgroundTaskManager.applyEfficiencyResources(request); backgroundTaskManager.applyEfficiencyResources(request);
console.info("applyEfficiencyResources success. "); console.info("applyEfficiencyResources success. ");
} catch (error) { } catch (error) {
console.error(`applyEfficiencyResources failed. code is ${error.code} message is ${error.message}`); console.error(`applyEfficiencyResources failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
## 导入模块 ## 导入模块
```js ```ts
import workScheduler from '@ohos.resourceschedule.workScheduler'; import workScheduler from '@ohos.resourceschedule.workScheduler';
``` ```
...@@ -42,8 +42,8 @@ startWork(work: WorkInfo): void ...@@ -42,8 +42,8 @@ startWork(work: WorkInfo): void
**示例** **示例**
```js ```ts
let workInfo = { let workInfo: workScheduler.WorkInfo = {
workId: 1, workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false, isRepeat: false,
...@@ -61,7 +61,7 @@ startWork(work: WorkInfo): void ...@@ -61,7 +61,7 @@ startWork(work: WorkInfo): void
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 as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
...@@ -93,8 +93,8 @@ stopWork(work: WorkInfo, needCancel?: boolean): void ...@@ -93,8 +93,8 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
**示例** **示例**
```js ```ts
let workInfo = { let workInfo: workScheduler.WorkInfo = {
workId: 1, workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW, batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false, isRepeat: false,
...@@ -112,7 +112,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void ...@@ -112,7 +112,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
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 as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
...@@ -144,20 +144,14 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void ...@@ -144,20 +144,14 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
**示例** **示例**
```js ```ts
try{ workScheduler.getWorkStatus(50, (error: BusinessError, res: workScheduler.WorkInfo) => {
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) { console.info(`workschedulerLog getWorkStatus success, ${JSON.stringify(res)}`);
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
} }
}); });
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
...@@ -193,18 +187,12 @@ getWorkStatus(workId: number): Promise\<WorkInfo> ...@@ -193,18 +187,12 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
**示例** **示例**
```js ```ts
try{ workScheduler.getWorkStatus(50).then((res: workScheduler.WorkInfo) => {
workScheduler.getWorkStatus(50).then((res) => { console.info(`workschedulerLog getWorkStatus success, ${JSON.stringify(res)}`);
for (let item in res) { }).catch((error: BusinessError) => {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
}).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}`);
}) })
} catch (error) {
console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
...@@ -239,18 +227,14 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo> ...@@ -239,18 +227,14 @@ obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
**示例** **示例**
```js ```ts
try{ workScheduler.obtainAllWorks((error: BusinessError, res: Array<workScheduler.WorkInfo>) =>{
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) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
...@@ -279,16 +263,12 @@ obtainAllWorks(): Promise\<Array\<WorkInfo>> ...@@ -279,16 +263,12 @@ obtainAllWorks(): Promise\<Array\<WorkInfo>>
**示例** **示例**
```js ```ts
try{ workScheduler.obtainAllWorks().then((res: Array<workScheduler.WorkInfo>) => {
workScheduler.obtainAllWorks().then((res) => {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}).catch((error) => { }).catch((error: BusinessError) => {
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}`);
}) })
} catch (error) {
console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.stopAndClearWorks ## workScheduler.stopAndClearWorks
...@@ -311,12 +291,12 @@ stopAndClearWorks(): void ...@@ -311,12 +291,12 @@ stopAndClearWorks(): void
**示例** **示例**
```js ```ts
try{ try{
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 as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
...@@ -354,18 +334,14 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean ...@@ -354,18 +334,14 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
**示例** **示例**
```js ```ts
try{ workScheduler.isLastWorkTimeOut(500, (error: BusinessError, res: boolean) =>{
workScheduler.isLastWorkTimeOut(500, (error, res) =>{
if (error) { if (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}`);
} else { } else {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
} }
}); });
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
...@@ -401,18 +377,14 @@ isLastWorkTimeOut(workId: number): Promise\<boolean> ...@@ -401,18 +377,14 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>
**示例** **示例**
```js ```ts
try{
workScheduler.isLastWorkTimeOut(500) workScheduler.isLastWorkTimeOut(500)
.then(res => { .then((res: boolean) => {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
}) })
.catch(error => { .catch((error: BusinessError) => {
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}`);
}); });
} catch (error) {
console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`);
}
``` ```
## WorkInfo ## WorkInfo
......
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
private context: Context = getContext(this); private context: Context = getContext(this);
startContinuousTask() { startContinuousTask() {
let wantAgentInfo: wantAgent.wantAgentInfo = { let wantAgentInfo: wantAgent.WantAgentInfo = {
// 点击通知后,将要执行的动作列表 // 点击通知后,将要执行的动作列表
wants: [ wants: [
{ {
...@@ -353,7 +353,7 @@ ...@@ -353,7 +353,7 @@
import { BusinessError } from '@ohos.base'; import { BusinessError } from '@ohos.base';
``` ```
4. 申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消。 4. 申请和取消长时任务。在 ServiceAbility 中,调用 startBackgroundRunning() 接口和 startBackgroundRunning() 接口实现长时任务的申请和取消,通过js代码实现
```js ```js
function startContinuousTask() { function startContinuousTask() {
......
...@@ -121,7 +121,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -121,7 +121,7 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
```ts ```ts
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
import workScheduler fron '@ohos.resourceschedule.workScheduler'; import workScheduler from '@ohos.resourceschedule.workScheduler';
``` ```
3. 实现WorkSchedulerExtension生命周期接口。 3. 实现WorkSchedulerExtension生命周期接口。
...@@ -184,8 +184,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -184,8 +184,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try { try {
workScheduler.startWork(this.workInfo); workScheduler.startWork(this.workInfo);
console.info(`startWork success`); console.info(`startWork success`);
} catch (error: BusinessError) { } catch (error) {
console.error(`startWork failed. code is ${error.code} message is ${error.message}`); console.error(`startWork failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
...@@ -202,8 +202,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则: ...@@ -202,8 +202,8 @@ WorkInfo参数用于设置应用条件,参数设置时需遵循以下规则:
try { try {
workScheduler.stopWork(this.workInfo); workScheduler.stopWork(this.workInfo);
console.info(`stopWork success`); console.info(`stopWork success`);
} catch (error: BusinessError) { } catch (error) {
console.error(`stopWork failed. code is ${error.code} message is ${error.message}`); console.error(`stopWork failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册