The **WorkSchedulerExtensionAbility** module provides callbacks for deferred task scheduling.
When developing an application, you can override the APIs of this module and add your own task logic to the APIs.
The **WorkSchedulerExtensionAbility** module provides callbacks for deferred task scheduling. You can override the APIs provided by this module. When a deferred task is triggered, the system calls back the application through the APIs and processes the task logic in the callback.
> **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.
## Modules to Import
```ts
...
...
@@ -36,7 +34,7 @@ Called when the system starts scheduling the deferred task.
The **distributedMissionManager** module implements system mission management across devices. You can use the APIs provided by this module to register or deregister a mission status listener, start or stop synchronizing a remote mission list, and continue a mission on a remote device.
The **distributedMissionManager** module implements mission management across devices. You can use the APIs provided by this module to register or deregister a mission status listener, start or stop synchronizing a remote mission list, and continue a mission on a remote device by mission ID or bundle name.
> **NOTE**
>
...
...
@@ -14,7 +14,6 @@ The **distributedMissionManager** module implements system mission management ac
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for.|
| options | [MissionCallback](#missioncallback) | Yes | Callback to register.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
| options | [MissionCallback](#missioncallback) | Yes | Callback to register.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the listener is registered, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
...
...
@@ -80,14 +79,14 @@ Registers a mission status listener. This API uses a promise to return the resul
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the listener is deregistered, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
...
...
@@ -159,7 +157,6 @@ Deregisters a mission status listener. This API uses an asynchronous callback to
| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the synchronization is started, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
...
...
@@ -257,7 +254,7 @@ Starts to synchronize the remote mission list. This API uses a promise to return
| Type | Description |
| ------------------- | ---------------- |
| Promise<void> | Promise used to return the result.|
| Promise<void> | Promise that returns no value.|
**Example**
...
...
@@ -294,7 +291,7 @@ Stops synchronizing the remote mission list. This API uses an asynchronous callb
| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the synchronization is stopped, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
...
...
@@ -334,7 +331,7 @@ Stops synchronizing the remote mission list. This API uses a promise to return t
| Type | Description |
| ------------------- | ---------------- |
| Promise<void> | Promise used to return the result.|
| Promise<void> | Promise that returns no value.|
**Example**
...
...
@@ -358,7 +355,7 @@ Stops synchronizing the remote mission list. This API uses a promise to return t
| options | [ContinueCallback](js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the mission is continued, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
...
...
@@ -416,7 +413,7 @@ For details about the error codes, see [Distributed Scheduler Error Codes](../er
| callback | AsyncCallback<void> | Yes | Callback invoked when the mission continuation is complete.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the mission is continued, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
...
...
@@ -546,7 +543,7 @@ Continues a mission on a remote device, with the bundle name specified. This API
| Type | Description |
| ------------------- | ---------------- |
| Promise<void> | Promise used to return the result.|
| Promise<void> | Promise that returns no value.|
**Error codes**
...
...
@@ -586,7 +583,7 @@ For details about the error codes, see [Distributed Scheduler Error Codes](../er
| type | string | Yes | Type of the listener. The value is fixed at **'continueStateChange'**. |
| callback | Callback<{ state: [ContinueState](#continuestate10), info: [ContinuableInfo](./js-apis-inner-application-continuableInfo.md) }> | Yes | Callback used to return the mission continuation state and information. |
| type | string | Yes | Event type. The value **'continueStateChange'** indicates the continuation state change event of the current mission. |
| callback | Callback<{ state: [ContinueState](#continuestate10), info: [ContinuableInfo](./js-apis-inner-application-continuableInfo.md) }> | Yes | Callback used to return the continuation state and information of the current mission. |
**Example**
...
...
@@ -615,7 +612,7 @@ Registers a listener for the mission continuation state of the current applicati
| type | string | Yes | Type of the listener. The value is fixed at **'continueStateChange'**. |
| callback | Callback<{ state: [ContinueState](#continuestate10), info: [ContinuableInfo](./js-apis-inner-application-continuableInfo.md) }> | No | Callback used for the listener to be deregistered. |
| type | string | Yes | Event type. The value **'continueStateChange'** indicates the continuation state change event of the current mission. |
| callback | Callback<{ state: [ContinueState](#continuestate10), info: [ContinuableInfo](./js-apis-inner-application-continuableInfo.md) }> | No | Callback used to return the continuation state and information of the current mission.<br>If the callback is unspecified, all subscriptions to the specified event are canceled. |
**Example**
...
...
@@ -688,5 +685,5 @@ Enumerates the mission continuation states.
The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent.
You can use the APIs to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background when your application is frozen or exits.
The **reminderAgentManager** module provides APIs related to agent-powered reminders. When your application is frozen or exits, the timing and notification functions of your application will be taken over by a system service running in the background. You can use the APIs to create scheduled reminders for countdown timers, calendar events, and alarm clocks.
> **NOTE**
>
...
...
@@ -15,12 +13,15 @@ You can use the APIs to create scheduled reminders for countdown timers, calenda
Publishes a reminder through the reminder agent. This API uses an asynchronous callback to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8).
Publishes a reminder. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API can be called only after the [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8) permission is obtained.
Publishes a reminder through the reminder agent. This API uses a promise to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8).
Publishes a reminder. This API uses a promise to return the result.
> **NOTE**
>
> This API can be called only after the [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8) permission is obtained.
@@ -124,7 +128,7 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| reminderId | number | Yes| ID of the reminder to cancel.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the reminder is canceled, **err** is **undefined**. Otherwise, **err** is an error object.|
@@ -208,7 +210,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)>> | Yes| Asynchronous callback used to return an array of all valid reminders set by the current application.|
| callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)>> | Yes| Callback used to return all the valid reminders.|
@@ -325,7 +326,7 @@ Cancels all reminders set by the current application. This API uses an asynchron
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If all the reminders are canceled, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes**
...
...
@@ -351,12 +352,11 @@ try {
};
```
## reminderAgentManager.cancelAllReminders
cancelAllReminders(): Promise\<void>
Cancels all reminders set by the current application. This API uses a promise to return the cancellation result.
Cancels all reminders set by the current application. This API uses a promise to return the result.
@@ -364,7 +364,7 @@ Cancels all reminders set by the current application. This API uses a promise to
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
| Promise\<void> | Promise that returns no value.|
**Error codes**
...
...
@@ -401,8 +401,8 @@ Adds a notification slot. This API uses an asynchronous callback to return the r
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot. Only the type can be set.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the notification slot is added, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
...
...
@@ -438,13 +438,13 @@ Adds a notification slot. This API uses a promise to return the result.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.|
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot. Only the type can be set.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise\<void> | Promise used to return the result.|
| Promise\<void> | Promise that returns no value.|
@@ -479,7 +479,7 @@ Removes a notification slot of a specified type. This API uses an asynchronous c
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the notification slot is removed, **err** is **undefined**. Otherwise, **err** is an error object.|
@@ -573,7 +572,7 @@ Defines a button displayed for the reminder in the notification panel.
| -------- | -------- | -------- | -------- |
| title | string | Yes| Text on the button.|
| type | [ActionButtonType](#actionbuttontype) | Yes| Button type.|
| wantAgent<sup>10+</sup> | [WantAgent](#wantagent) | No| Ability information that is displayed after the button is clicked.<br>**System API**: This is a system API and cannot be called by third-party applications.|
| wantAgent<sup>10+</sup> | [WantAgent](#wantagent) | No| Information about the ability that is displayed after the button is clicked.<br>**System API**: This is a system API and cannot be called by third-party applications.|
## WantAgent
...
...
@@ -592,19 +591,19 @@ Defines the information about the redirected-to ability.
## MaxScreenWantAgent
Provides the information about the target package and ability to start automatically when the reminder is displayed in full-screen mode. This API is reserved.
Provides the information about the ability that is started automatically and displayed in full-screen mode when the reminder arrives. This API is reserved.
@@ -613,7 +612,7 @@ Defines the reminder to publish.
| reminderType | [ReminderType](#remindertype) | Yes| Type of the reminder.|
| actionButton<sup></sup> | [ActionButton](#actionbutton) | No| Buttons displayed for the reminder in the notification panel.<br>- For common applications, a maximum of two buttons are supported.<br>- For system applications, a maximum of two buttons are supported in API version 9, and a maximum of three buttons are supported in API version 10 and later versions.|
| wantAgent | [WantAgent](#wantagent) | No| Information about the ability that is redirected to when the reminder is clicked.|
| maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | No| Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.|
| maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | No| Information about the ability that is started automatically and displayed in full-screen mode when the reminder arrives. If the device is in use, only a notification banner is displayed.<br> This API is reserved.|
| ringDuration | number | No| Ringing duration, in seconds. The default value is **1**.|
| snoozeTimes | number | No| Number of reminder snooze times. The default value is **0**.|
| timeInterval | number | No| Reminder snooze interval, in seconds. The minimum value is 5 minutes.|
...
...
@@ -623,8 +622,8 @@ Defines the reminder to publish.
| snoozeContent | string | No| Content to be displayed when the reminder is snoozing.|
| notificationId | number | No| Notification ID used by the reminder. If there are reminders with the same notification ID, the later one will overwrite the earlier one.|
| slotType | [notification.SlotType](js-apis-notificationManager.md#slottype) | No| Type of the slot used by the reminder.|
| tapDismissed<sup>10+</sup> | boolean | No| Whether the notification is automatically cleared. The value is the same as that of [NotificationRequest.tapDismissed](js-apis-inner-notification-notificationRequest.md#notificationrequest).|
| autoDeletedTime<sup>10+</sup> | number | No| Time when the notification is automatically cleared. The value is the same as that of[NotificationRequest.autoDeletedTime](js-apis-inner-notification-notificationRequest.md#notificationrequest).|
| tapDismissed<sup>10+</sup> | boolean | No| Whether the reminder is automatically cleared. For details, see [NotificationRequest.tapDismissed](js-apis-inner-notification-notificationRequest.md#notificationrequest). |
| autoDeletedTime<sup>10+</sup> | number | No| Time when the reminder is automatically cleared. For details, see[NotificationRequest.autoDeletedTime](js-apis-inner-notification-notificationRequest.md#notificationrequest).|
The **workScheduler** module provides the APIs for registering, canceling, and querying deferred tasks.
The system schedules and executes deferred tasks at an appropriate time, subject to the storage space, power consumption, temperature, and more.
The **workScheduler** module provides the APIs for registering, canceling, and querying deferred tasks. You can use the APIs to register tasks that do not have high requirements on real-time performance as deferred tasks. The system schedules and executes the deferred tasks at an appropriate time, subject to the storage space, power consumption, 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 deferred task scheduling, see [Constraints](../../task-management/work-scheduler.md#constraints).
## Modules to Import
...
...
@@ -18,9 +15,10 @@ import workScheduler from '@ohos.resourceschedule.workScheduler';
```
## workScheduler.startWork
startWork(work: WorkInfo): void
Instructs the WorkSchedulerService to add a task to the execution queue.
| work | [WorkInfo](#workinfo) | Yes | Task to stop. |
| needCancel | boolean | No | Whether to cancel the task. The default value is **false**.|
| work | [WorkInfo](#workinfo) | Yes | Deferred task to stop.|
| needCancel | boolean | No | Whether to clear the task while stopping it.<br>The value **true** means to clear the task while stopping it, and **false** means to stop the task only. The default value is **false**.|
**Error codes**
...
...
@@ -119,9 +117,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
| callback | AsyncCallback\<[WorkInfo](#workinfo)> | Yes | Callback used to return the result. If the specified task ID is valid, the task status obtained from the WorkSchedulerService is returned. Otherwise, an exception is thrown.|
| workId | number | Yes | ID of the deferred task. |
| callback | AsyncCallback\<[WorkInfo](#workinfo)> | Yes | Callback used to return the result. If **workId** is valid, the task information obtained from WorkSchedulerService is returned. Otherwise, an exception is thrown.|
**Error codes**
...
...
@@ -162,9 +161,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
```
## workScheduler.getWorkStatus
getWorkStatus(workId: number): Promise\<WorkInfo>
Obtains the latest task status. This API uses a promise to return the result.
Obtains the information a deferred task. This API uses a promise to return the result.
| Promise\<[WorkInfo](#workinfo)> | Promise used to return the result. If the specified task ID is valid, the task status obtained from the WorkSchedulerService is returned. Otherwise, an exception is thrown.|
| Promise\<[WorkInfo](#workinfo)> | Promise used to return the result. If **workId** is valid, the task information obtained from WorkSchedulerService is returned.|
**Error codes**
...
...
@@ -208,9 +208,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If all the deferred tasks are obtained, **err** is **undefined**. Otherwise, **err** is an error object.|
| Promise\<boolean> | Promise used to return the result. If the last execution of the task timed out, **true** is returned. Otherwise, **false** is returned.|
| Promise\<boolean> | Promise used to return the result. The value **true** means that the last execution of the specified task times out, and **false** means the opposite.|
**Error codes**
...
...
@@ -411,31 +416,33 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
```
## WorkInfo
Provides detailed information about the task. For details about the constraints on setting the **WorkInfo** parameter, see [Constraints](../../task-management/work-scheduler.md#constraints).
| workId | number | Yes | ID of the deferred task. |
| bundleName | string | Yes | Bundle name of the application that requests the task. |
| abilityName | string | Yes | Name of the component to be notified by a deferred task scheduling callback.|
| networkType | [NetworkType](#networktype) | No | Network type. |
| isCharging | boolean | No | Whether the device is charging. |
| isCharging | boolean | No | Whether the device needs to enter the charging state to trigger deferred task scheduling.<br>The value **true** means that the device needs to enter the charging state to trigger deferred task scheduling, and **false** means the opposite.|
| chargerType | [ChargingType](#chargingtype) | No | Charging type. |
| batteryLevel | number | No | Battery level. |
| 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.|
| isRepeat | boolean | No | Whether the task is repeated.<br>The value** true** means that the task is repeated, and **false** means the opposite.|
| 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]: number \| string \| boolean} | No | Carried parameters. |
| isPersisted | boolean | No | Whether to enable persistent storage for the task.<br>The value **true** means to enable persistent storage for the task, and **false** means the opposite.|
| isDeepIdle | boolean | No | Whether the device needs to enter the idle state to trigger deferred task scheduling.<br>The value **true** means that the device needs to enter the idle state to trigger deferred task scheduling, and **false** means the opposite. |
| idleWaitTime | number | No | Time to wait in the idle state before triggering deferred task scheduling. |
| parameters | [key: string]: number \| string \| boolean | No | Carried parameters.|
## NetworkType
Enumerates the network types that can trigger task scheduling.
Enumerates the network types that can trigger deferred task scheduling.
| getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void; | Obtains the status of a deferred task. This API uses an asynchronous callback to return the result.|
| getWorkStatus(workId: number): Promise<WorkInfo>; | Obtains the status of a deferred task. This API uses a promise to return the result.|
| getWorkStatus(workId: number, callback: AsyncCallback<WorkInfo>): void; | Obtains the information about a deferred task. This API uses an asynchronous callback to return the result.|
| getWorkStatus(workId: number): Promise<WorkInfo>; | Obtains the information about a deferred task. This API uses a promise to return the result.|
| obtainAllWorks(callback: AsyncCallback<void>): Array<WorkInfo>; | Obtains all the deferred tasks. This API uses an asynchronous callback to return the result.|
| obtainAllWorks(): Promise<Array<WorkInfo>>; | Obtains all the deferred tasks. This API uses a promise to return the result.|
| stopAndClearWorks(): void; | Stops and clears all the deferred tasks.|
...
...
@@ -77,7 +77,7 @@ The table below lists the APIs used for developing deferred tasks. For details a
| bundleName | string | Bundle name of the application that requests the deferred task.|
| abilityName | string | Name of the ability to be notified by a deferred task scheduling callback. This parameter is mandatory.|