未验证 提交 3807d2f5 编写于 作者: O openharmony_ci 提交者: Gitee

!12697 翻译完成:11853+11880+12113+12250+11919+11891+11934

Merge pull request !12697 from wusongqing/TR11880
......@@ -200,6 +200,7 @@
- [@ohos.data.dataSharePredicates](js-apis-data-dataSharePredicates.md)
- [@ohos.data.dataShareResultSet](js-apis-data-DataShareResultSet.md)
- [@ohos.data.distributedDataObject](js-apis-data-distributedobject.md)
- [@ohos.data.distributedKVStore](js-apis-distributedKVStore.md)
- [@ohos.data.preferences](js-apis-data-preferences.md)
- [@ohos.data.rdb](js-apis-data-rdb.md)
- [@ohos.data.ValuesBucket](js-apis-data-ValuesBucket.md)
......@@ -288,6 +289,7 @@
- [@ohos.runningLock](js-apis-runninglock.md)
- [@ohos.sensor](js-apis-sensor.md)
- [@ohos.settings](js-apis-settings.md)
- [@ohos.stationary](js-apis-stationary.md)
- [@ohos.systemParameterV9](js-apis-system-parameterV9.md)
- [@ohos.thermal](js-apis-thermal.md)
- [@ohos.update](js-apis-update.md)
......@@ -342,7 +344,6 @@
- [@ohos.reminderAgent](js-apis-reminderAgent.md)
- [@ohos.systemParameter](js-apis-system-parameter.md)
- [@ohos.usb](js-apis-usb-deprecated.md)
- [@ohos.workScheduler](js-apis-workScheduler.md)
- [@system.app](js-apis-system-app.md)
- [@system.battery](js-apis-system-battery.md)
- [@system.bluetooth](js-apis-system-bluetooth.md)
......
# Background Task Management
# @ohos.backgroundTaskManager (Background Task Management)
The **BackgroundTaskManager** module provides APIs to manage background tasks.
......@@ -161,7 +161,7 @@ Requests a continuous task from the system. This API uses an asynchronous callba
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
......@@ -253,7 +253,7 @@ Requests a continuous task from the system. This API uses a promise to return th
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| bgMode | [BackgroundMode](#backgroundmode8) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. |
......@@ -339,7 +339,7 @@ Requests to cancel a continuous task. This API uses an asynchronous callback to
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
......@@ -395,7 +395,7 @@ Requests to cancel a continuous task. This API uses a promise to return the resu
| Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
**Return value**
......@@ -452,14 +452,14 @@ Provides the information about the suspension delay.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
| Name | Description |
| ----------------------- | --------------------- |
| DATA_TRANSFER | Data transfer. |
| AUDIO_PLAYBACK | Audio playback. |
| AUDIO_RECORDING | Audio recording. |
| LOCATION | Positioning and navigation. |
| BLUETOOTH_INTERACTION | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | Multi-device connection. |
| WIFI_INTERACTION | WLAN-related (system API).|
| VOIP | Audio and video calls (system API). |
| TASK_KEEPING | Computing task (effective only for specific devices). |
| Name | Value | Description |
| ----------------------- | ---- | --------------------- |
| DATA_TRANSFER | 1 | Data transfer. |
| AUDIO_PLAYBACK | 2 | Audio playback. |
| AUDIO_RECORDING | 3 | Audio recording. |
| LOCATION | 4 | Positioning and navigation. |
| BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. |
| WIFI_INTERACTION | 7 | WLAN-related.<br>This is a system API.|
| VOIP | 8 | Audio and video calls.<br>This is a system API. |
| TASK_KEEPING | 9 | Computing task (effective only for specific devices). |
# Configuration Policy
# @ohos.configPolicy (Configuration Policy)
The **configPolicy** module provides APIs for obtaining the custom configuration directory and file path based on the predefined custom configuration level.
......@@ -24,6 +24,7 @@ For example, if the **config.xml** file is stored in **/system/etc/config.xml**
**System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------- |
| relPath | string | Yes | Name of the configuration file. |
......@@ -50,11 +51,13 @@ Obtains the path of a configuration file with the specified name and highest pri
**System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ----- |
| relPath | string | Yes | Name of the configuration file.|
**Return value**
| Type | Description |
| --------------------- | ------------ |
| Promise&lt;string&gt; | Promise used to return the path of the configuration file.|
......@@ -79,6 +82,7 @@ For example, if the **config.xml** file is stored in **/system/etc/config.xml**
**System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------- |
| relPath | string | Yes | Name of the configuration file. |
......@@ -105,11 +109,13 @@ Obtains a list of configuration files with the specified name, sorted in ascendi
**System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ----- |
| relPath | string | Yes | Name of the configuration file.|
**Return value**
| Type | Description |
| ---------------------------------- | ---- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the file list.|
......@@ -133,6 +139,7 @@ Obtains the list of configuration level directories. This API uses an asynchrono
**System capability**: SystemCapability.Customization.ConfigPolicy
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback used to return the configuration level directory list.|
......@@ -158,6 +165,7 @@ Obtains the list of configuration level directories. This API uses a promise to
**System capability**: SystemCapability.Customization.ConfigPolicy
**Return value**
| Type | Description |
| ---------------------------------- | -------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the configuration level directory list.|
......
# Background Task Management
# @ohos.resourceschedule.backgroundTaskManager (Background Task Management)
The **BackgroundTaskManager** module provides APIs to manage background tasks.
......@@ -234,7 +234,7 @@ Requests a continuous task from the system. This API uses an asynchronous callba
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| bgMode | [BackgroundMode](#backgroundmode) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
......@@ -308,7 +308,7 @@ Requests a continuous task from the system. This API uses a promise to return th
| Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| bgMode | [BackgroundMode](#backgroundmode) | Yes | Background mode requested. |
| wantAgent | [WantAgent](js-apis-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. |
......@@ -381,7 +381,7 @@ Requests to cancel a continuous task. This API uses an asynchronous callback to
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Error codes**
......@@ -437,7 +437,7 @@ Requests to cancel a continuous task. This API uses a promise to return the resu
| Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- |
| context | Context | Yes | Application context.<br>For the application context of the FA model, see [Context](js-apis-Context.md).<br>For the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
**Return value**
......@@ -618,12 +618,12 @@ Enumerates the efficiency resource types.
**System API**: This is a system API.
| Name | Description |
| ----------------------- | --------------------- |
| CPU | CPU resources, which prevent the application from being suspended. |
| COMMON_EVENT | A type of software resources, which prevent common events from being proxied when the application is suspended. |
| TIMER | A type of software resources, which prevent timers from being proxied when the application is suspended. |
| WORK_SCHEDULER | WORK_SCHEDULER resources, which ensure that the application has more time to execute the task. |
| BLUETOOTH | A type of hardware resources, which prevent Bluetooth resources from being proxied when the application is suspended. |
| GPS | A type of hardware resources, which prevent GPS resources from being proxied when the application is suspended. |
| AUDIO | A type of hardware resources, which prevent audio resources from being proxied when the application is suspended.|
| Name | Value | Description |
| ----------------------- | ---- | --------------------- |
| CPU | 1 | CPU resources, which prevent the application from being suspended. |
| COMMON_EVENT | 2 | A type of software resources, which prevent common events from being proxied when the application is suspended. |
| TIMER | 4 | A type of software resources, which prevent timers from being proxied when the application is suspended. |
| WORK_SCHEDULER | 8 | WORK_SCHEDULER resources, which ensure that the application has more time to execute the task. |
| BLUETOOTH | 16 | A type of hardware resources, which prevent Bluetooth resources from being proxied when the application is suspended. |
| GPS | 32 | A type of hardware resources, which prevent GPS resources from being proxied when the application is suspended. |
| AUDIO | 64 | A type of hardware resources, which prevent audio resources from being proxied when the application is suspended.|
# Work Scheduler
# @ohos.resourceschedule.workScheduler
The **workScheduler** module provides the APIs for registering, canceling, and querying Work Scheduler tasks, which do not have real-time constraints.
......@@ -437,45 +437,45 @@ Enumerates the network types that can trigger the task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Description |
| ---------------------- | ----------------------- |
| NETWORK_TYPE_ANY | Any network type. |
| NETWORK_TYPE_MOBILE | Mobile network. |
| NETWORK_TYPE_WIFI | Wi-Fi network. |
| NETWORK_TYPE_BLUETOOTH | Bluetooth network.|
| NETWORK_TYPE_WIFI_P2P | Wi-Fi P2P network. |
| NETWORK_TYPE_ETHERNET | Ethernet. |
| Name | Value | Description |
| ---------------------- | ---- | ----------------------- |
| 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.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Description |
| ------------------------- | -------------------- |
| CHARGING_PLUGGED_ANY | Any charging type.|
| CHARGING_PLUGGED_AC | DC charging. |
| CHARGING_PLUGGED_USB | USB charging. |
| CHARGING_PLUGGED_WIRELESS | Wireless charging. |
| Name | Value | Description |
| ------------------------- | ---- | -------------------- |
| 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 states that can trigger the task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Description |
| -------------------------- | -------------------------- |
| BATTERY_STATUS_LOW | A low battery alert is displayed. |
| BATTERY_STATUS_OKAY | The battery level is restored from low to normal. |
| BATTERY_STATUS_LOW_OR_OKAY | The battery level is restored from low to normal, or a low battery alert is displayed.|
| Name | Value | Description |
| -------------------------- | ---- | -------------------------- |
| 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 states that can trigger the task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Description |
| ------------------------- | ------------------------------ |
| STORAGE_LEVEL_LOW | The storage space is insufficient. |
| STORAGE_LEVEL_OKAY | The storage space is restored from insufficient to normal. |
| STORAGE_LEVEL_LOW_OR_OKAY | The storage space is restored from insufficient to normal, or the storage space is insufficient.|
| Name | Value | Description |
| ------------------------- | ---- | ------------------------------ |
| STORAGE_LEVEL_LOW | 0 | The storage space is insufficient. |
| STORAGE_LEVEL_OKAY | 1 | The storage space is restored from insufficient to normal. |
| STORAGE_LEVEL_LOW_OR_OKAY | 2 | The storage space is restored from insufficient to normal, or the storage space is insufficient.|
# @ohos.stationary (Device Status Awareness Framework)
The **stationary** module provides APIs to report the device status, including absolute still and relative still.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import stationary from '@ohos.stationary'
```
## ActivityResponse
Defines the response interface to receive the device status.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
### Attributes
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| state | [ActivityState](#activitystate) | Yes| No| New device status.|
## ActivityType
Enumerates the device status types.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
| Name| Description|
| -------- | -------- |
| still | Absolutely still.|
| relativeStill | Relatively still.|
## ActivityEvent
Enumerates the device status events.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
| Name | Value | Description |
| ------------------------------ | ---- | ---------------------------------------- |
| ENTER | 1 | Event indicating entering device status. |
| EXIT | 2 | Event indicating exiting device status.|
| ENTER_EXIT | 3 | Event indicating entering and exiting device status.|
## ActivityState
Enumerates the device statuses.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
| Name | Value | Description |
| ------------------------------ | ---- | ---------------------------------------- |
| ENTER | 1 | Entering device status. |
| EXIT | 2 | Exiting device status.|
## stationary.on('still' | 'relativeStill')
on(activity: ActivityType, event: ActivityEvent, reportLatencyNs: number, callback: Callback&lt;ActivityResponse&gt;): void
Subscribes to the device status.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
| activity | [ActivityType](#activitytype) | Yes | Device status type. |
| event | [ActivityEvent](#activityevent) | Yes | Event type. |
| reportLatencyNs | number | Yes | Event reporting period. |
| callback | Callback<[ActivityResponse](#activityresponse)\> | Yes | Callback used to receive reported data. |
**Example**
```js
var reportLatencyNs = 100;
stationary.on('still', stationary.ActivityEvent.ENTER, reportLatencyNs, (data) => {
console.log('data='+ JSON.stringify(data));
})
```
## stationary.once('still' | 'relativeStill')
once(activity: ActivityType, callback: Callback&lt;ActivityResponse&gt;): void
Obtains the device status.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
| activity | [ActivityType](#activitytype) | Yes | Device status type. |
| callback | Callback<[ActivityResponse](#activityresponse)\> | Yes | Callback used to receive reported data. |
**Example**
```js
stationary.once('still', (data) => {
console.log("data="+ JSON.stringify(data));
})
```
## stationary.off('still' | 'relativeStill')
off(activity: ActivityType, event: ActivityEvent, callback?: Callback&lt;ActivityResponse&gt;): void
Unsubscribes from the device status.
**System capability**: SystemCapability.Msdp.DeviceStatus.Stationary
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | -------------------------------------------------- | ---- | ---------------------------- |
| activity | [ActivityType](#activitytype) | Yes | Device status type. |
| event | [ActivityEvent](#activityevent) | Yes | Event type. |
| callback | Callback<[ActivityResponse](#activityresponse)\> | No | Callback used to receive reported data. |
**Example**
```js
stationary.off('still', stationary.ActivityEvent.ENTER);
```
# Work Scheduler
The **workScheduler** module provides the APIs for registering, canceling, and querying Work Scheduler tasks, which do not have real-time constraints.
The system executes Work Scheduler tasks at an appropriate time, subject to the storage space, power consumption, temperature, and more.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module can be used only in the stage model.
> - For details about the constraints on the Work Scheduler usage, see [Work Scheduler Overview](../../task-management/work-scheduler-overview.md).
## Modules to Import
```js
import workScheduler from '@ohos.workScheduler';
```
## workScheduler.startWork
startWork(work: WorkInfo): boolean
Instructs the **WorkSchedulerService** to add the specified task to the execution queue.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | --------------------- | ---- | -------------- |
| work | [WorkInfo](#workinfo) | Yes | Task to be added to the execution queue.|
**Return value**
| Type | Description |
| ------- | -------------------------------- |
| boolean | Returns **true** if the task is added to the execution queue; returns **false** otherwise.|
**Example**
```js
let workInfo = {
workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false,
isPersisted: true,
bundleName: "com.example.myapplication",
abilityName: "MyExtension",
parameters: {
mykey0: 1,
mykey1: "string value",
mykey2: true,
mykey3: 1.5
}
}
var res = workScheduler.startWork(workInfo);
console.info(`workschedulerLog res: ${res}`);
```
## workScheduler.stopWork
stopWork(work: WorkInfo, needCancel?: boolean): boolean
Instructs the **WorkSchedulerService** to stop the specified task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | --------------------- | ---- | ---------- |
| work | [WorkInfo](#workinfo) | Yes | Task to stop. |
| needCancel | boolean | Yes | Whether to cancel the task.|
**Return value**
| Type | Description |
| ------- | ----------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
let workInfo = {
workId: 1,
batteryStatus:workScheduler.BatteryStatus.BATTERY_STATUS_LOW,
isRepeat: false,
isPersisted: true,
bundleName: "com.example.myapplication",
abilityName: "MyExtension",
parameters: {
mykey0: 1,
mykey1: "string value",
mykey2: true,
mykey3: 1.5
}
}
var res = workScheduler.stopWork(workInfo, false);
console.info(`workschedulerLog res: ${res}`);
```
## workScheduler.getWorkStatus
getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
Obtains the latest task status. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------- |
| workId | number | Yes | Task ID. |
| 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**
```js
workScheduler.getWorkStatus(50, (err, res) => {
if (err) {
console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`);
} else {
for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
}
});
```
## workScheduler.getWorkStatus
getWorkStatus(workId: number): Promise\<WorkInfo>
Obtains the latest task status. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | -------- |
| workId | number | Yes | Task ID.|
**Return value**
| Type | Description |
| ------------------------------- | ---------------------------------------- |
| 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**
```js
workScheduler.getWorkStatus(50).then((res) => {
for (let item in res) {
console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`);
}
}).catch((err) => {
console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`);
})
```
## workScheduler.obtainAllWorks
obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
Obtains all tasks associated with this application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return all tasks associated with the current application. |
**Return value**
| Type | Description |
| ----------------------------- | --------------- |
| Array\<[WorkInfo](#workinfo)> | All tasks associated with the current application.|
**Example**
```js
workScheduler.obtainAllWorks((err, res) =>{
if (err) {
console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`);
} else {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}
});
```
## workScheduler.obtainAllWorks
obtainAllWorks(): Promise<Array\<WorkInfo>>
Obtains all tasks associated with this application. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Return value**
| Type | Description |
| -------------------------------------- | ------------------------------ |
| Promise<Array\<[WorkInfo](#workinfo)>> | Promise used to return all tasks associated with the current application. |
**Example**
```js
workScheduler.obtainAllWorks().then((res) => {
console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`);
}).catch((err) => {
console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`);
})
```
## workScheduler.stopAndClearWorks
stopAndClearWorks(): boolean
Stops and cancels all tasks associated with the current application.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Example**
```js
let res = workScheduler.stopAndClearWorks();
console.info(`workschedulerLog res: ${res}`);
```
## workScheduler.isLastWorkTimeOut
isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
Checks whether the last execution of the specified task timed out. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------------------------------- |
| workId | number | Yes | Task ID. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Callback used to return the result. Returns **true** if the last execution of the specified task timed out; returns **false** otherwise.|
**Example**
```js
workScheduler.isLastWorkTimeOut(500, (err, res) =>{
if (err) {
console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`);
} else {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
}
});
```
## workScheduler.isLastWorkTimeOut
isLastWorkTimeOut(workId: number): Promise\<boolean>
Checks whether the last execution of the specified task timed out. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | -------- |
| workId | number | Yes | Task ID.|
**Return value**
| 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.|
**Example**
```js
workScheduler.isLastWorkTimeOut(500)
.then(res => {
console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`);
})
.catch(err => {
console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`);
});
```
## WorkInfo
Provides detailed information about the task. For details about the constraints on configuring **WorkInfo**, see [Work Scheduler Overview](../../task-management/work-scheduler-overview.md).
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Type | Mandatory | Description |
| --------------- | --------------------------------- | ---- | ---------------- |
| workId | number | Yes | Task ID. |
| 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.|
| networkType | [NetworkType](#networktype) | No | Network type. |
| isCharging | boolean | No | Whether the device is charging. |
| chargerType | [ChargingType](#chargingtype) | No | Charging type. |
| batteryLevel | number | No | Battery level. |
| batteryStatus | [BatteryStatus](#batterystatus) | No | Battery status. |
| storageRequest | [StorageRequest](#storagerequest) | No | Storage status. |
| isRepeat | boolean | No | Whether the task is repeated. |
| repeatCycleTime | number | No | Repeat interval. |
| repeatCount | number | No | Number of repeat times. |
| isPersisted | boolean | No | Whether to enable persistent storage for the task. |
| isDeepIdle | boolean | No | Whether the device needs to enter the idle state. |
| idleWaitTime | number | No | Time to wait in the idle state. |
| parameters | {[key: string]: any} | No | Carried parameters. |
## NetworkType
Enumerates the network types that can trigger the task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Default Value | Description |
| ---------------------- | ---- | ----------------------- |
| 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.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Default Value | Description |
| ------------------------- | ---- | -------------------- |
| 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 states that can trigger the task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Default Value | Description |
| -------------------------- | ---- | -------------------------- |
| 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 states that can trigger the task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Default Value | Description |
| ------------------------- | ---- | ------------------------------ |
| STORAGE_LEVEL_LOW | 0 | The storage space is insufficient. |
| STORAGE_LEVEL_OKAY | 1 | The storage space is restored from insufficient to normal. |
| STORAGE_LEVEL_LOW_OR_OKAY | 2 | The storage space is restored from insufficient to normal, or the storage space is insufficient.|
......@@ -15,6 +15,7 @@
- [Window Error Codes](errorcode-window.md)
- Media
- [Audio Error Codes](errorcode-audio.md)
- [Media Error Codes](errorcode-media.md)
- [AVSession Management Error Codes](errorcode-avsession.md)
- Resource Management
- [I18N Error Codes](errorcode-i18n.md)
......@@ -34,6 +35,12 @@
- [Upload and Download Error Codes](errorcode-request.md)
- Basic Features
- [FaultLogger Error Codes](errorcode-faultlogger.md)
- [Application Event Logging Error Codes](errorcode-hiappevent.md)
- [HiSysEvent Error Codes](errorcode-hisysevent.md)
- [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md)
- [Input Method Framework Error Codes](errorcode-inputmethod-framework.md)
- [Pasteboard Error Codes](errorcode-pasteboard.md)
- [Webview Error Codes](errorcode-webview.md)
- Account Management
- [Account Error Codes](errorcode-account.md)
- [App Account Error Codes](errorcode-app-account.md)
......@@ -43,6 +50,7 @@
- [Sensor Error Codes](errorcode-sensor.md)
- [Vibrator Error Codes](errorcode-vibrator.md)
- [System Parameter Error Codes](errorcode-system-parameterV9.md)
- [USB Error Codes](errorcode-usb.md)
- Language Base Class Library
- [Buffer Error Codes](errorcode-buffer.md)
- [containers Error Codes](errorcode-containers.md)
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册