未验证 提交 14141c0d 编写于 作者: O openharmony_ci 提交者: Gitee

!2344 2061 处理完成:js-apis-workScheduler.md 刷新

Merge pull request !2344 from ester.zhou/TR-2061
...@@ -11,30 +11,27 @@ import workScheduler from '@ohos.workScheduler' ...@@ -11,30 +11,27 @@ import workScheduler from '@ohos.workScheduler'
``` ```
## workScheduler.startWork ## workScheduler.startWork
- **System capability** startWork(work: WorkInfo): boolean
SystemCapability.ResourceSchedule.WorkScheduler
- **API**
workScheduler.startWork(work: WorkInfo): boolean
- **Description**
Instructs the **WorkSchedulerService** to add the specified task to the execution queue. Instructs the **WorkSchedulerService** to add the specified task to the execution queue.
- **Parameters** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ---- | --------------------- | ---- | -------------- |
| work | WorkInfo | Yes| Task to be added to the execution queue.| | work | [WorkInfo](#workinfo) | Yes | Task to be added to the execution queue.|
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | -------------------------------- |
| boolean | Returns **true** if the task is added to the execution queue; returns **false** otherwise.| | boolean | Returns **true** if the task is added to the execution queue; returns **false** otherwise.|
- **Example** **Example**
``` ```
let workInfo = { let workInfo = {
workId: 1, workId: 1,
batteryLevel:50, batteryLevel:50,
...@@ -46,34 +43,31 @@ Instructs the **WorkSchedulerService** to add the specified task to the executio ...@@ -46,34 +43,31 @@ Instructs the **WorkSchedulerService** to add the specified task to the executio
} }
var res = workScheduler.startWork(workInfo); var res = workScheduler.startWork(workInfo);
console.info("workschedulerLog res:" + res); console.info("workschedulerLog res:" + res);
``` ```
## workScheduler.stopWork ## workScheduler.stopWork
- **System capability**
SystemCapability.ResourceSchedule.WorkScheduler
- **API**
stopWork(work: WorkInfo, needCancel?: boolean): boolean stopWork(work: WorkInfo, needCancel?: boolean): boolean
- **Description**
Instructs the **WorkSchedulerService** to stop the specified task. Instructs the **WorkSchedulerService** to stop the specified task.
- **Parameters** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ---------- | --------------------- | ---- | ---------- |
| work | WorkInfo | Yes| Task to stop.| | work | [WorkInfo](#workinfo) | Yes | Task to stop. |
|needCancel|boolean| Yes| Whether to cancel the task.| | needCancel | boolean | Yes | Whether to cancel the task.|
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | ----------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- **Example** **Example**
``` ```
let workInfo = { let workInfo = {
workId: 1, workId: 1,
batteryLevel:50, batteryLevel:50,
...@@ -85,29 +79,25 @@ Instructs the **WorkSchedulerService** to stop the specified task. ...@@ -85,29 +79,25 @@ Instructs the **WorkSchedulerService** to stop the specified task.
} }
var res = workScheduler.stopWork(workInfo, false); var res = workScheduler.stopWork(workInfo, false);
console.info("workschedulerLog res:" + res); console.info("workschedulerLog res:" + res);
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
- **System capability** getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
SystemCapability.ResourceSchedule.WorkScheduler
- **API** Obtains the latest task status. This API uses an asynchronous callback to return the result.
getWorkStatus(workId: number, callback : AsyncCallback<WorkInfo>): void
- **Description** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
Obtains the latest task status. This method uses an asynchronous callback to return the result.
- **Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | ------------------------------------- | ---- | ---------------------------------------- |
| workId | number | Yes| Task ID.| | workId | number | Yes | Task ID. |
|callback|AsyncCallback<WorkInfo>| Yes| Callback used to return the result. Returns the task status obtained from the **WorkSchedulerService** if the specified task ID is valid; returns **null** otherwise.| | callback | AsyncCallback\<[WorkInfo](#workinfo)> | Yes | Callback used to return the result. Returns the task status obtained from the **WorkSchedulerService** if the specified task ID is valid; returns **null** otherwise.|
**Example**
- **Example** ```
```
workScheduler.getWorkStatus(50, (err, res) => { workScheduler.getWorkStatus(50, (err, res) => {
if (err) { if (err) {
console.info('workschedulerLog getWorkStatus failed, because:' + err.data); console.info('workschedulerLog getWorkStatus failed, because:' + err.data);
...@@ -117,33 +107,30 @@ Obtains the latest task status. This method uses an asynchronous callback to ret ...@@ -117,33 +107,30 @@ Obtains the latest task status. This method uses an asynchronous callback to ret
} }
} }
}); });
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
- **System capability** getWorkStatus(workId: number): Promise\<WorkInfo>
SystemCapability.ResourceSchedule.WorkScheduler
- **API** Obtains the latest task status. This API uses a promise to return the result.
getWorkStatus(workID: number): Promise<WorkInfo>
- **Description** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
Obtains the latest task status. This method uses a promise to return the result.
- **Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ------ | ------ | ---- | -------- |
| workId | number | Yes| Task ID.| | workId | number | Yes | Task ID.|
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------------------- | ---------------------------------------- |
| Promise<WorkInfo> | Promise used to return the result. Returns the task status obtained from the **WorkSchedulerService** if the specified task ID is valid; returns **null** otherwise.| | Promise\<[WorkInfo](#workinfo)> | Promise used to return the result. Returns the task status obtained from the **WorkSchedulerService** if the specified task ID is valid; returns **null** otherwise.|
- **Example** **Example**
``` ```
workScheduler.getWorkStatus(50).then((res) => { workScheduler.getWorkStatus(50).then((res) => {
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]);
...@@ -151,34 +138,30 @@ Obtains the latest task status. This method uses a promise to return the result. ...@@ -151,34 +138,30 @@ Obtains the latest task status. This method uses a promise to return the result.
}).catch((err) => { }).catch((err) => {
console.info('workschedulerLog getWorkStatus failed, because:' + err.data); console.info('workschedulerLog getWorkStatus failed, because:' + err.data);
}) })
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
- **System capability** obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
SystemCapability.ResourceSchedule.WorkScheduler
- **API**
obtainAllWorks(callback : AsyncCallback<void>): Array<WorkInfo>
- **Description** Obtains all tasks associated with this application. This API uses an asynchronous callback to return the result.
Obtains all tasks associated with this application. This method uses an asynchronous callback to return the result.
- **Parameters** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name| Type| Mandatory| Description| **Parameters**
| -------- | -------- | -------- | -------- |
|callback|AsyncCallback<WorkInfo>| Yes| Callback used to return all tasks associated with the current application.|
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return all tasks associated with the current application.|
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ----------------------------- | --------------- |
| Array<WorkInfo> | All tasks associated with the current application.| | Array\<[WorkInfo](#workinfo)> | All tasks associated with the current application.|
- **Example** **Example**
``` ```
workScheduler.obtainAllWorks((err, res) =>{ workScheduler.obtainAllWorks((err, res) =>{
if (err) { if (err) {
console.info('workschedulerLog obtainAllWorks failed, because:' + err.data); console.info('workschedulerLog obtainAllWorks failed, because:' + err.data);
...@@ -186,77 +169,68 @@ Obtains all tasks associated with this application. This method uses an asynchro ...@@ -186,77 +169,68 @@ Obtains all tasks associated with this application. This method uses an asynchro
console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res)); console.info('workschedulerLog obtainAllWorks success, data is:' + JSON.stringify(res));
} }
}); });
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
- **System capability** obtainAllWorks(): Promise<Array\<WorkInfo>>
SystemCapability.ResourceSchedule.WorkScheduler
- **API** Obtains all tasks associated with this application. This API uses a promise to return the result.
obtainAllWorks(): Promise<Array<WorkInfo>>
- **Description** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
Obtains all tasks associated with this application. This method uses a promise to return the result.
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | -------------------------------------- | ------------------------------ |
| Promise<Array<WorkInfo>> | Promise used to return all tasks associated with the current application.| | Promise<Array\<[WorkInfo](#workinfo)>> | Promise used to return all tasks associated with the current application.|
- **Example** **Example**
``` ```
workScheduler.obtainAllWorks().then((res) => { 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((err) => { }).catch((err) => {
console.info('workschedulerLog obtainAllWorks failed, because:' + err.data); console.info('workschedulerLog obtainAllWorks failed, because:' + err.data);
}) })
``` ```
## workScheduler.stopAndClearWorks ## workScheduler.stopAndClearWorks
- **System capability**
SystemCapability.ResourceSchedule.WorkScheduler
- **API**
stopAndClearWorks(): boolean stopAndClearWorks(): boolean
- **Description**
Stops and cancels all tasks associated with the current application. Stops and cancels all tasks associated with the current application.
- **Example** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
``` **Example**
```
let res = workScheduler.stopAndClearWorks(); let res = workScheduler.stopAndClearWorks();
console.info("workschedulerLog res:" + res); console.info("workschedulerLog res:" + res);
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
- **System capability** isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
SystemCapability.ResourceSchedule.WorkScheduler
- **API** Checks whether the last execution of the specified task timed out. This API uses an asynchronous callback to return the result.
isLastWorkTimeOut(workId: number, callback : AsyncCallback<void>): boolean
- **Description** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
Checks whether the last execution of the specified task timed out. This method uses an asynchronous callback to return the result.
- **Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------------------- | ---- | ---------------------------------------- |
| workId | number | Yes| Task ID.| | workId | number | Yes | Task ID. |
|callback|AsyncCallback<WorkInfo>| Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------- | ---------------------------------------- |
| boolean | Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.| | boolean | Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.|
- **Example** **Example**
``` ```
workScheduler.isLastWorkTimeOut(500, (err, res) =>{ workScheduler.isLastWorkTimeOut(500, (err, res) =>{
if (err) { if (err) {
console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data);
...@@ -264,33 +238,30 @@ Checks whether the last execution of the specified task timed out. This method u ...@@ -264,33 +238,30 @@ Checks whether the last execution of the specified task timed out. This method u
console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res); console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res);
} }
}); });
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
- **System capability** isLastWorkTimeOut(workId: number): Promise\<boolean>
SystemCapability.ResourceSchedule.WorkScheduler
- **API** Checks whether the last execution of the specified task timed out. This API uses a promise to return the result.
isLastWorkTimeOut(workId: number): Promise<boolean>
- **Description** **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
Checks whether the last execution of the specified task timed out. This method uses a promise to return the result.
- **Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | ------ | ------ | ---- | -------- |
| workId | number | Yes| Task ID.| | workId | number | Yes | Task ID.|
- **Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ----------------- | ---------------------------------------- |
| Promise<boolean> | Promise used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.| | Promise\<boolean> | Promise used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.|
- **Example** **Example**
``` ```
workScheduler.isLastWorkTimeOut(500) workScheduler.isLastWorkTimeOut(500)
.then(res => { .then(res => {
console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res); console.info('workschedulerLog isLastWorkTimeOut success, data is:' + res);
...@@ -298,77 +269,71 @@ Checks whether the last execution of the specified task timed out. This method u ...@@ -298,77 +269,71 @@ Checks whether the last execution of the specified task timed out. This method u
.catch(err => { .catch(err => {
console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data); console.info('workschedulerLog isLastWorkTimeOut failed, because:' + err.data);
}); });
}) ```
```
## workScheduler.WorkInfo
- **System capability**
SystemCapability.ResourceSchedule.WorkScheduler
## WorkInfo
Provides detailed information about the task. Provides detailed information about the task.
| Name| Type| Mandatory| Description| **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| -------- | -------- | -------- | -------- |
|workId |number |Yes|Task ID.| | Name | Type | Mandatory | Description |
|bundleName |string |Yes| Name of the Work Scheduler task bundle.| | --------------- | --------------------------------- | ---- | ---------------- |
|abilityName | string| Yes| Name of the component to be notified by a Work Scheduler callback.| | workId | number | Yes | Task ID. |
|networkType | NetworkType| No| Network type.| | bundleName | string | Yes | Name of the Work Scheduler task bundle. |
|isCharging | bool| No|Whether the device is charging.| | abilityName | string | Yes | Name of the component to be notified by a Work Scheduler callback.|
|chargerType | ChargingType| No|Charging type.| | networkType | [NetworkType](#networktype) | No | Network type. |
|batteryLevel | number| No|Battery level.| | isCharging | boolean | No | Whether the device is charging. |
|batteryStatus| BatteryStatus| No|Battery status.| | chargerType | [ChargingType](#chargingtype) | No | Charging type. |
|storageRequest|StorageRequest| No|Storage status.| | batteryLevel | number | No | Battery level. |
|isRepeat|boolean|No|Whether the task is repeated.| | batteryStatus | [BatteryStatus](#batterystatus) | No | Battery status. |
|repeatCycleTime |number|No|Repeat interval.| | storageRequest | [StorageRequest](#storagerequest) | No | Storage status. |
|repeatCount |number|No|Number of repeat times.| | isRepeat | boolean | No | Whether the task is repeated. |
| repeatCycleTime | number | No | Repeat interval. |
## workScheduler.NetworkType | repeatCount | number | No | Number of repeat times. |
- **System capability**
SystemCapability.ResourceSchedule.WorkScheduler ## NetworkType
Enumerates the network types that can trigger the task. Enumerates the network types that can trigger the task.
|Name|Default Value|Description| **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| -------- | -------- | -------- |
|NETWORK_TYPE_ANY |0 |Any network type.|
|NETWORK_TYPE_MOBILE |1| Mobile network.|
|NETWORK_TYPE_WIFI |2 |Wi-Fi network.|
|NETWORK_TYPE_BLUETOOTH |3 |Bluetooth network.|
|NETWORK_TYPE_WIFI_P2P |4 |Wi-Fi P2P network.|
|NETWORK_TYPE_ETHERNET |5 |Ethernet.|
## workScheduler.ChargingType | Name | Default Value | Description |
- **System capability** | ---------------------- | ---- | ----------------------- |
SystemCapability.ResourceSchedule.WorkScheduler | NETWORK_TYPE_ANY | 0 | Any network type. |
| NETWORK_TYPE_MOBILE | 1 | Mobile network. |
| NETWORK_TYPE_WIFI | 2 | Wi-Fi network. |
| NETWORK_TYPE_BLUETOOTH | 3 | Bluetooth network.|
| NETWORK_TYPE_WIFI_P2P | 4 | Wi-Fi P2P network. |
| NETWORK_TYPE_ETHERNET | 5 | Ethernet. |
## ChargingType
Enumerates the charging types that can trigger the task. Enumerates the charging types that can trigger the task.
|Name|Default Value|Description| **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| -------- | -------- | -------- |
|CHARGING_PLUGGED_ANY |0| Any charging type.|
|CHARGING_PLUGGED_AC |1 |DC charging.|
|CHARGING_PLUGGED_USB |2 |USB charging.|
|CHARGING_PLUGGED_WIRELESS |3| Wireless charging.|
## workScheduler.BatteryStatus | Name | Default Value | Description |
- **System capability** | ------------------------- | ---- | -------------------- |
SystemCapability.ResourceSchedule.WorkScheduler | CHARGING_PLUGGED_ANY | 0 | Any charging type.|
| CHARGING_PLUGGED_AC | 1 | DC charging. |
| CHARGING_PLUGGED_USB | 2 | USB charging. |
| CHARGING_PLUGGED_WIRELESS | 3 | Wireless charging. |
## BatteryStatus
Enumerates the battery status that can trigger the task. Enumerates the battery status that can trigger the task.
|Name|Default Value|Description| **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| -------- | -------- | -------- |
|BATTERY_STATUS_LOW |0 |A low battery alert is displayed.|
|BATTERY_STATUS_OKAY |1| The battery level is restored from low to normal.|
|BATTERY_STATUS_LOW_OR_OKAY |2 |The battery level is restored from low to normal, or a low battery alert is displayed.|
## workScheduler.StorageRequest | Name | Default Value | Description |
- **System capability** | -------------------------- | ---- | -------------------------- |
SystemCapability.ResourceSchedule.WorkScheduler | BATTERY_STATUS_LOW | 0 | A low battery alert is displayed. |
| BATTERY_STATUS_OKAY | 1 | The battery level is restored from low to normal. |
| BATTERY_STATUS_LOW_OR_OKAY | 2 | The battery level is restored from low to normal, or a low battery alert is displayed.|
## StorageRequest
Enumerates the storage status that can trigger the task. Enumerates the storage status that can trigger the task.
|Name|Default Value|Description| **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
|Name |Default Value |Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
|STORAGE_LEVEL_LOW |0 |The storage space is insufficient. |STORAGE_LEVEL_LOW |0 |The storage space is insufficient.
|STORAGE_LEVEL_OKAY |1 |The storage space is restored from insufficient to normal. |STORAGE_LEVEL_OKAY |1 |The storage space is restored from insufficient to normal.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册