diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 15041298fa9ae42688243622b2267ed7a0d9e017..bb3eca101141cf2fcc13c880bc7edd69173d02d7 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -113,6 +113,7 @@ - [ServiceExtensionContext](js-apis-inner-application-serviceExtensionContext.md) - [UIAbilityContext](js-apis-inner-application-uiAbilityContext.md) - [shellCmdResult](js-apis-inner-application-shellCmdResult.md) + - [WindowExtensionContext](js-apis-inner-application-windowExtensionContext.md) - wantAgent - [triggerInfo](js-apis-inner-wantAgent-triggerInfo.md) - [wantAgentInfo](js-apis-inner-wantAgent-wantAgentInfo.md) diff --git a/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md b/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md index 6080d2c9bc52e30b6fa987f9cb65ea9b42a28024..c05f331ad7f1fa1a9db31080bd1cc06ad9767054 100644 --- a/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md +++ b/en/application-dev/reference/apis/js-apis-backgroundTaskManager.md @@ -187,7 +187,7 @@ let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "com.example.myapplication.MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -207,7 +207,7 @@ Stage model: ```ts import UIAbility from '@ohos.app.ability.UIAbility'; import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import wantAgent from '@ohos.wantAgent'; +import wantAgent from '@ohos.app.ability.wantAgent'; function callback(err, data) { if (err) { @@ -276,7 +276,7 @@ let wantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", - abilityName: "EntryAbility" + abilityName: "com.example.myapplication.MainAbility" } ], operationType: wantAgent.OperationType.START_ABILITY, @@ -299,7 +299,7 @@ Stage model: ```ts import UIAbility from '@ohos.app.ability.UIAbility'; import backgroundTaskManager from '@ohos.backgroundTaskManager'; -import wantAgent from '@ohos.wantAgent'; +import wantAgent from '@ohos.app.ability.wantAgent'; export default class EntryAbility extends UIAbility { onCreate(want, launchParam) { diff --git a/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md b/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md index d5daa5d41e299d368b7d38af4428856bf343c516..9ff197787fb1ce1eaaab9f26f993edef2f364ea3 100644 --- a/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md +++ b/en/application-dev/reference/apis/js-apis-resourceschedule-backgroundTaskManager.md @@ -52,10 +52,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -100,10 +100,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -156,10 +156,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -201,10 +201,10 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9900001 | Caller information verification failed for a transient task. | -| 9900002 | Transient task verification failed. | +| 9900001 | Caller information verification failed. | +| 9900002 | Background task verification failed. | **Example** @@ -247,9 +247,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | @@ -258,7 +258,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er ```js import UIAbility from '@ohos.app.ability.UIAbility'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; -import wantAgent from '@ohos.wantAgent'; +import wantAgent from '@ohos.app.ability.wantAgent'; function callback(error, data) { if (error) { @@ -282,14 +282,18 @@ export default class EntryAbility extends UIAbility { wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; - wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - try { - backgroundTaskManager.startBackgroundRunning(this.context, - backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback) - } catch (error) { - console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); - } - }); + try { + wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { + try { + backgroundTaskManager.startBackgroundRunning(this.context, + backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback) + } catch (error) { + console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); + } + }); + } catch (error) { + console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`); + } } }; ``` @@ -326,9 +330,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | @@ -337,7 +341,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er ```js import UIAbility from '@ohos.app.ability.UIAbility'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; -import wantAgent from '@ohos.wantAgent'; +import wantAgent from '@ohos.app.ability.wantAgent'; export default class EntryAbility extends UIAbility { onCreate(want, launchParam) { @@ -353,18 +357,22 @@ export default class EntryAbility extends UIAbility { wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] }; - wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - try { - backgroundTaskManager.startBackgroundRunning(this.context, - backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => { - console.info("Operation startBackgroundRunning succeeded"); - }).catch((error) => { + try { + wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { + try { + backgroundTaskManager.startBackgroundRunning(this.context, + backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => { + console.info("Operation startBackgroundRunning succeeded"); + }).catch((error) => { + console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); + }); + } catch (error) { console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); - }); - } catch (error) { - console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`); - } - }); + } + }); + } catch (error) { + console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`); + } } }; ``` @@ -392,9 +400,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | @@ -453,9 +461,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 9800005 | Continuous task verification failed. | +| 9800005 | Background task verification failed. | | 9800006 | Notification verification failed. | | 9800007 | Task storage failed. | @@ -506,9 +514,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 18700001 | Caller information verification failed when applying for efficiency resources. | +| 18700001 | Caller information verification failed. | **Example** @@ -549,9 +557,9 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er | ---- | --------------------- | | 9800001 | Memory operation failed. | | 9800002 | Parcel operation failed. | -| 9800003 | IPC failed. | | +| 9800003 | Inner transact failed. | | | 9800004 | System service operation failed. | -| 18700001 | Caller information verification failed when applying for efficiency resources. | +| 18700001 | Caller information verification failed. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md b/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md index 0e7ad7e7c38f32e85af6ab3504252da38afb32eb..736335322cef1ebb094100d2ac566b0520adf8c7 100644 --- a/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md +++ b/en/application-dev/reference/apis/js-apis-resourceschedule-workScheduler.md @@ -39,7 +39,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | | 9700005 | StartWork failed. | @@ -80,7 +80,7 @@ Instructs the **WorkSchedulerService** to stop the specified task. | Name | Type | Mandatory | Description | | ---------- | --------------------- | ---- | ---------- | | work | [WorkInfo](#workinfo) | Yes | Task to stop. | -| needCancel | boolean | Yes | Whether to cancel the task.| +| needCancel | boolean | No | Whether to cancel the task.| **Error codes** @@ -91,7 +91,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | **Example** @@ -141,7 +141,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | **Example** @@ -189,7 +189,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes | 9700001 | Memory operation failed. | | 9700002 | Parcel operation failed. | | 9700003 | System service operation failed. | -| 9700004 | Checking workInfo failed. | +| 9700004 | Check workInfo failed. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-workScheduler.md b/en/application-dev/reference/apis/js-apis-workScheduler.md deleted file mode 100644 index d897bc91717348ee8addd00751741f83cc77c345..0000000000000000000000000000000000000000 --- a/en/application-dev/reference/apis/js-apis-workScheduler.md +++ /dev/null @@ -1,361 +0,0 @@ -# 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\): 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\ - -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\): Array\ - -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\ | 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> - -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> | 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\): 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\ | 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\ - -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\ | 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.| diff --git a/en/application-dev/task-management/workscheduler-extensionability.md b/en/application-dev/task-management/workscheduler-extensionability.md index 9f7547fcb317389dcb4791190ef3d5bcd211ec32..f33f3be98868dc3c8d7890eb50ba127133749d98 100644 --- a/en/application-dev/task-management/workscheduler-extensionability.md +++ b/en/application-dev/task-management/workscheduler-extensionability.md @@ -44,7 +44,7 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: Import the module. ```ts - import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility' + import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'; ``` Implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. @@ -53,27 +53,27 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: export default class workAbility extends WorkSchedulerExtensionAbility { // Callback invoked when the Work Scheduler task starts. onWorkStart(workInfo) { - console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`) + console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`); // Publish an upgrade notification. - let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, '') + let notificationRequest = notification.getNotificationContentBasic('upgrade', upgradeMessage, ''); notification.publish(notificationRequest, (err) => { if (err) { - console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`) + console.log(`onWorkStart notification publish err ${JSON.stringify(err)}`); } - console.log(`onWorkStart notification publish success`) - }) + console.log(`onWorkStart notification publish success`); + }); } // Callback invoked when the Work Scheduler task stops. onWorkStop(workInfo) { // Publish an upgrade completion notification. - let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', '') + let notificationRequest = notification.getNotificationContentBasic('upgrade', 'upgrade success', ''); notification.publish(notificationRequest, (err) => { if (err) { - console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`) + console.log(`onWorkStop notification publish err ${JSON.stringify(err)}`); } - console.log(`onWorkStop notification publish success`) - }) + console.log(`onWorkStop notification publish success`); + }); } } ``` @@ -82,25 +82,25 @@ To create a WorkScheduler project in DevEco Studio, perform the following steps: Import the module. - ```ts - import { workAbility } from '@ohos/library' - ``` + ```ts + import { workAbility } from '@ohos/library'; + ``` Inherit from **workAbility** and implement the lifecycle callbacks for the WorkSchedulerExtensionAbility. - ```ts + ```ts export default class WorkTest extends workAbility { onWorkStart(workInfo) { - console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`) - super.onWorkStart(workInfo) + console.log(`onWorkStartTest start ${JSON.stringify(workInfo)}`); + super.onWorkStart(workInfo); } - - onWorkStopTest(workInfo) { - super.onWorkStop(workInfo) - console.log(`onWorkStop value`) + + onWorkStopTest(workInfo) { + super.onWorkStop(workInfo); + console.log(`onWorkStop value`); } } - ``` + ``` ### Implementing Work Scheduler @@ -109,7 +109,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS Import the module. ```ts - import workScheduler from '@ohos.resourceschedule.workScheduler' + import workScheduler from '@ohos.resourceschedule.workScheduler'; ``` Encapsulate the APIs for starting and stopping Work Scheduler tasks. @@ -124,13 +124,13 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS } // Start the Work Scheduler task. startWork(bundleName: string, abilityName: string) { - this.workInfo.bundleName = bundleName - this.workInfo.abilityName = abilityName + this.workInfo.bundleName = bundleName; + this.workInfo.abilityName = abilityName; try { - workScheduler.startWork(this.workInfo) - console.log(`startWork success`) + workScheduler.startWork(this.workInfo); + console.log(`startWork success`); } catch (error) { - Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`) + Logger.error(TAG, `startWork startwork failed. code is ${error.code} message is ${error.message}`); prompt.showToast({ message: `${error.message}` }) @@ -139,10 +139,10 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS // Stop the Work Scheduler task. stopWork(bundleName: string, abilityName: string) { - this.workInfo.bundleName = bundleName - this.workInfo.abilityName = abilityName - workScheduler.stopWork(this.workInfo, false) - console.log(`stopWork`) + this.workInfo.bundleName = bundleName; + this.workInfo.abilityName = abilityName; + workScheduler.stopWork(this.workInfo, false); + console.log(`stopWork`); } } ``` @@ -152,7 +152,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS Import the module. ```ts - import { workAbility } from '@ohos/library' + import { workAbility } from '@ohos/library'; ``` Add the **Upgrade** button, which, when being clicked, will call the API encapsulated in **library** to start the Work Scheduler task. In the API, **bundleName** and **abilityName** are passed in, where the value of **abilityName** is **WorkTest**. @@ -163,7 +163,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS .height(40) .fontSize(30) .onClick(() => { - this.work.startWork('ohos.samples.workscheduler', 'WorkTest') + this.work.startWork('ohos.samples.workscheduler', 'WorkTest'); }) ``` @@ -171,7 +171,7 @@ Inherit from **workAbility** and implement the lifecycle callbacks for the WorkS ```ts aboutToDisappear() { - this.work.stopWork('ohos.samples.workscheduler', 'WorkTest') + this.work.stopWork('ohos.samples.workscheduler', 'WorkTest'); } ```