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

!13787 删除API9旧接口,回合monthly

Merge pull request !13787 from 朱天怡/monthly_20221018
......@@ -383,7 +383,6 @@
- [@ohos.reminderAgent (后台代理提醒)](js-apis-reminderAgent.md)
- [@ohos.systemParameter (系统属性)](js-apis-system-parameter.md)
- [@ohos.usb (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)
......
......@@ -205,7 +205,7 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent';
......@@ -297,7 +297,7 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent';
......@@ -365,7 +365,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callbac
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
function callback(err, data) {
......@@ -422,7 +422,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(()
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import Ability from '@ohos.application.Ability';
import backgroundTaskManager from '@ohos.backgroundTaskManager';
export default class MainAbility extends Ability {
......@@ -436,69 +436,6 @@ export default class MainAbility extends Ability {
};
```
## backgroundTaskManager.applyEfficiencyResources<sup>9+</sup>
applyEfficiencyResources(request: [EfficiencyResourcesRequest](#efficiencyresourcesrequest9)): boolean
向系统申请或释放能效资源,使用boolean形式返回结果。
通过EfficiencyResourcesRequest参数中的isApply变量,设置是申请还是释放。
应用使用此接口,需要向应用中心申请获得相应特权。
进程和它所属的应用可以同时申请某一类资源,例如CPU资源,但是应用释放资源的时候会将进程的资源一起释放。
**系统能力**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
**系统API**: 此接口为系统接口。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ---------------------------------------- |
| request | [EfficiencyResourcesRequest](#efficiencyresourcesrequest9) | 是 | 请求的必要信息。包括资源类型,超时时间等信息。详见[EfficiencyResourcesRequest](#efficiencyresourcesrequest9)。 |
**返回值**
| 类型 | 说明 |
| -------------- | ---------------- |
| boolean | true代表申请成功,false代表申请失败。 |
**示例**
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let request = {
resourceTypes: backgroundTaskManager.ResourceType.CPU,
// 如果将isApply置为false,则表示释放资源
isApply: true,
timeOut: 0,
reason: "apply",
isPersist: true,
isProcess: false,
};
let res = backgroundTaskManager.applyEfficiencyResources(request);
console.info("result of applyEfficiencyResources is: " + res)
```
## backgroundTaskManager.resetAllEfficiencyResources<sup>9+</sup>
resetAllEfficiencyResources(): void
释放所有已经申请的资源。
应用使用此接口,需要向应用中心申请获得相应特权。
**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
**系统API**: 此接口为系统接口。
**示例**
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
backgroundTaskManager.resetAllEfficiencyResources();
```
## DelaySuspendInfo
延迟挂起信息。
......@@ -526,38 +463,3 @@ backgroundTaskManager.resetAllEfficiencyResources();
| WIFI_INTERACTION | 7 | WLAN相关<br />此接口为系统接口。 |
| VOIP | 8 | 音视频通话<br />此接口为系统接口。 |
| TASK_KEEPING | 9 | 计算任务(仅在特定设备生效)。 |
## EfficiencyResourcesRequest<sup>9+</sup>
能效资源申请参数。
**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
**系统API**: 此接口为系统接口。
| 名称 | 类型 | 必填 | 说明 |
| --------------- | ------ | ---- | ---------------------------------------- |
| resourceTypes | number | 是 | 申请的资源类型。 |
| isApply | boolean | 是 | 申请资源或者是释放资源。 |
| timeOut | number | 是 | 资源的使用时间,以毫秒为单位。 |
| isPersist | boolean | 否 | 是否永久持有资源,如果是true,那么timeOut就无效。 |
| isProcess | boolean | 否 | 应用申请或者是进程申请。 |
| reason | string | 是 | 申请资源的原因。 |
## ResourceType<sup>9+</sup>
能效资源类型。
**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
**系统API**: 此接口为系统接口。
| 名称 | 值 | 说明 |
| ----------------------- | ---- | --------------------- |
| CPU | 1 | CPU资源,申请后不被挂起。 |
| COMMON_EVENT | 2 | 公共事件,申请后挂起状态下不被代理掉。 |
| TIMER | 4 | 计时器,申请后挂起状态下不被代理掉。 |
| WORK_SCHEDULER | 8 | 延迟任务,申请后有更长的执行时间。 |
| BLUETOOTH | 16 | 蓝牙相关,申请后挂起状态下不被代理掉。 |
| GPS | 32 | GPS相关,申请后挂起状态下不被代理掉。 |
| AUDIO | 64 | 音频资源,申请后挂起状态下不被代理掉。 |
\ No newline at end of file
......@@ -51,10 +51,10 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
| ---- | --------------------- |
| 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. |
**示例**
......@@ -99,10 +99,10 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;):
| ---- | --------------------- |
| 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. |
**示例**
......@@ -155,10 +155,10 @@ getRemainingDelayTime(requestId: number): Promise&lt;number&gt;
| ---- | --------------------- |
| 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. |
**示例**
......@@ -200,10 +200,10 @@ cancelSuspendDelay(requestId: number): void
| ---- | --------------------- |
| 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. |
**示例**
......@@ -246,9 +246,9 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
| ---- | --------------------- |
| 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. |
......@@ -325,9 +325,9 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
| ---- | --------------------- |
| 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. |
......@@ -391,9 +391,9 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): vo
| ---- | --------------------- |
| 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. |
......@@ -452,9 +452,9 @@ stopBackgroundRunning(context: Context): Promise&lt;void&gt;
| ---- | --------------------- |
| 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. |
......@@ -505,9 +505,9 @@ applyEfficiencyResources(request: [EfficiencyResourcesRequest](#efficiencyresour
| ---- | --------------------- |
| 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. |
**示例**
......@@ -548,9 +548,9 @@ resetAllEfficiencyResources(): void
| ---- | --------------------- |
| 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. |
**示例**
......
......@@ -39,7 +39,7 @@ startWork(work: WorkInfo): void
| 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 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------- | ---- | ---------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 |
| needCancel | boolean | | 是否需要取消的工作。 |
| needCancel | boolean | | 是否需要取消的工作。 |
**错误码**
......@@ -91,7 +91,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): void
| 9700001 | Memory operation failed. |
| 9700002 | Parcel operation failed. |
| 9700003 | System service operation failed. |
| 9700004 | Checking workInfo failed. |
| 9700004 | Check workInfo failed. |
**示例**
......@@ -141,7 +141,7 @@ getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
| 9700001 | Memory operation failed. |
| 9700002 | Parcel operation failed. |
| 9700003 | System service operation failed. |
| 9700004 | Checking workInfo failed. |
| 9700004 | Check workInfo failed. |
**示例**
......@@ -189,7 +189,7 @@ getWorkStatus(workId: number): Promise\<WorkInfo>
| 9700001 | Memory operation failed. |
| 9700002 | Parcel operation failed. |
| 9700003 | System service operation failed. |
| 9700004 | Checking workInfo failed. |
| 9700004 | Check workInfo failed. |
**示例**
......
# 延迟任务调度
本模块提供延迟任务注册、取消、查询的能力。
开发者在开发应用时,通过调用延迟任务注册接口,注册对实时性要求不高的延迟任务,该任务默认由系统安排,在系统空闲时根据性能、功耗、热等情况进行调度执行。
> **说明:**
>
> - 从API Version 9 开始,该接口不再维护,推荐使用新接口[@ohos.resourceschedule.workScheduler (延迟任务调度)](js-apis-resourceschedule-workScheduler.md)。
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口仅可在Stage模型下使用。
> - 延迟任务调度约束见[延迟任务调度约束](../../task-management/background-task-overview.md#延迟任务调度约束)。
## 导入模块
```js
import workScheduler from '@ohos.workScheduler';
```
## workScheduler.startWork
startWork(work: WorkInfo): boolean
通知WorkSchedulerService将工作添加到执行队列。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 名称 | 类型 | 必填 | 说明 |
| ---- | --------------------- | ---- | -------------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 |
**返回值**
| 类型 | 说明 |
| ------- | -------------------------------- |
| boolean | 如果工作成功添加到执行队列,则返回true,否则返回false。 |
**示例**
```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
}
}
let res = workScheduler.startWork(workInfo);
console.info(`workschedulerLog res: ${res}`);
```
## workScheduler.stopWork
stopWork(work: WorkInfo, needCancel?: boolean): boolean
通知WorkSchedulerService停止指定工作。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 名称 | 类型 | 必填 | 说明 |
| ---------- | --------------------- | ---- | ---------- |
| work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 |
| needCancel | boolean | 是 | 是否需要取消的工作。 |
**返回值**
| 类型 | 说明 |
| ------- | ----------------------- |
| boolean | 如果成功,则返回true,否则返回false。 |
**示例**
```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
}
}
let res = workScheduler.stopWork(workInfo, false);
console.info(`workschedulerLog res: ${res}`);
```
## workScheduler.getWorkStatus
getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
获取工作的最新状态,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------- | ---- | ---------------------------------------- |
| workId | number | 是 | work的id。 |
| callback | AsyncCallback\<[WorkInfo](#workinfo)> | 是 | 指定的callback回调方法。如果指定的工作Id有效,则返回从WorkSchedulerService获取的有效工作状态;否则返回null。 |
**示例**
```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>
获取工作的最新状态,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| workId | number | 是 | work的id。 |
**返回值**
| 类型 | 说明 |
| ------------------------------- | ---------------------------------------- |
| Promise\<[WorkInfo](#workinfo)> | 指定的Promise回调方法。如果指定的工作ID有效,则返回从WorkSchedulerService获取的有效工作状态;否则返回null。 |
**示例**
```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>
获取与当前应用程序关联的所有工作,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------- |
| callback | AsyncCallback\<void> | 是 | 指定的callback回调方法。返回与应用程序关联的所有工作。 |
**返回值**
| 类型 | 说明 |
| ----------------------------- | --------------- |
| Array\<[WorkInfo](#workinfo)> | 返回与应用程序关联的所有工作。 |
**示例**
```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>>
获取与当前应用程序关联的所有工作,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**返回值**
| 类型 | 说明 |
| -------------------------------------- | ------------------------------ |
| Promise<Array\<[WorkInfo](#workinfo)>> | 指定的Promise回调方法。返回与应用程序关联的所有工作。 |
**示例**
```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
停止和取消与当前应用程序关联的所有工作。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**示例**
```js
let res = workScheduler.stopAndClearWorks();
console.info(`workschedulerLog res: ${res}`);
```
## workScheduler.isLastWorkTimeOut
isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
检查指定工作的最后一次执行是否为超时操作,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------------------- |
| workId | number | 是 | work的id。 |
| callback | AsyncCallback\<void> | 是 | 指定的callback回调方法。如果指定工作的最后一次执行是超时操作,则返回true;否则返回false。 |
**返回值**
| 类型 | 说明 |
| ------- | ---------------------------------------- |
| boolean | 指定的callback回调方法。如果指定工作的最后一次执行是超时操作,则返回true;否则返回false。 |
**示例**
```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>
检查指定工作的最后一次执行是否为超时操作,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
**参数**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| workId | number | 是 | work的id。 |
**返回值**
| 类型 | 说明 |
| ----------------- | ---------------------------------------- |
| Promise\<boolean> | 指定的Promise回调方法。如果指定工作的最后一次执行是超时操作,则返回true;否则返回false。 |
**示例**
```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
提供工作的具体信息。WorkInfo设置参数约束见[延迟任务调度概述](../../task-management/background-task-overview.md#延迟任务调度约束)
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 类型 | 必填 | 说明 |
| --------------- | --------------------------------- | ---- | ---------------- |
| workId | number | 是 | 当前工作的ID |
| bundleName | string | 是 | 延迟任务包名 |
| abilityName | string | 是 | 延迟任务回调通知的组件名(必填) |
| networkType | [NetworkType](#networktype) | 否 | 网络类型 |
| isCharging | boolean | 否 | 是否充电 |
| chargerType | [ChargingType](#chargingtype) | 否 | 充电类型 |
| batteryLevel | number | 否 | 电量 |
| batteryStatus | [BatteryStatus](#batterystatus) | 否 | 电池状态 |
| storageRequest | [StorageRequest](#storagerequest) | 否 | 存储状态 |
| isRepeat | boolean | 否 | 是否循环任务 |
| repeatCycleTime | number | 否 | 循环间隔 |
| repeatCount | number | 否 | 循环次数 |
| isPersisted | boolean | 否 | 是否持久化保存工作 |
| isDeepIdle | boolean | 否 | 是否要求设备进入空闲状态 |
| idleWaitTime | number | 否 | 空闲等待时间 |
| parameters | {[key: string]: any} | 否 | 携带参数信息 |
## NetworkType
触发工作的网络类型。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 值 | 说明 |
| ---------------------- | ---- | ----------------------- |
| NETWORK_TYPE_ANY | 0 | 表示这个触发条件是任何类型的网络连接。 |
| NETWORK_TYPE_MOBILE | 1 | 表示这个触发条件是Mobile网络连接。 |
| NETWORK_TYPE_WIFI | 2 | 表示这个触发条件是Wifi类型的网络连接。 |
| NETWORK_TYPE_BLUETOOTH | 3 | 表示这个触发条件是Bluetooth网络连接。 |
| NETWORK_TYPE_WIFI_P2P | 4 | 表示这个触发条件是Wifi P2P网络连接。 |
| NETWORK_TYPE_ETHERNET | 5 | 表示这个触发条件是有线网络连接。 |
## ChargingType
触发工作的充电类型。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 值 | 说明 |
| ------------------------- | ---- | -------------------- |
| CHARGING_PLUGGED_ANY | 0 | 表示这个触发条件是任何类型的充电器连接。 |
| CHARGING_PLUGGED_AC | 1 | 表示这个触发条件是直流充电器连接。 |
| CHARGING_PLUGGED_USB | 2 | 表示这个触发条件是USB充连接。 |
| CHARGING_PLUGGED_WIRELESS | 3 | 表示这个触发条件是无线充电器连接。 |
## BatteryStatus
触发工作的电池状态。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 值 | 说明 |
| -------------------------- | ---- | -------------------------- |
| BATTERY_STATUS_LOW | 0 | 表示这个触发条件是低电告警。 |
| BATTERY_STATUS_OKAY | 1 | 表示这个触发条件是从低电恢复到正常电量。 |
| BATTERY_STATUS_LOW_OR_OKAY | 2 | 表示这个触发条件是从低电恢复到正常电量或者低电告警。 |
## StorageRequest
触发工作的存储状态。
**系统能力**:SystemCapability.ResourceSchedule.WorkScheduler
| 名称 | 值 | 说明 |
| ------------------------- | ---- | ------------------------------ |
| STORAGE_LEVEL_LOW | 0 | 表示这个触发条件是存储空间不足。 |
| STORAGE_LEVEL_OKAY | 1 | 表示这个触发条件是从存储空间不足恢复到正常。 |
| STORAGE_LEVEL_LOW_OR_OKAY | 2 | 表示这个触发条件是从存储空间不足恢复到正常或者存储空间不足。 |
\ No newline at end of file
......@@ -43,7 +43,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility'
import WorkSchedulerExtensionAbility from '@ohos.WorkSchedulerExtensionAbility';
```
实现WorkSchedulerExtension生命周期接口。
......@@ -52,27 +52,27 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
export default class workAbility extends WorkSchedulerExtensionAbility {
// 延迟任务开始回调
onWorkStart(workInfo) {
console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`)
console.log(`onWorkStart CommonEvent publish start ${JSON.stringify(workInfo)}`);
// 发送升级通知
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`);
});
}
// 延迟任务结束回调
onWorkStop(workInfo) {
// 发送升级完成通知
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`);
});
}
}
```
......@@ -83,7 +83,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import { workAbility } from '@ohos/library'
import { workAbility } from '@ohos/library';
```
继承workAbility,实现WorkSchedulerExtension生命周期接口。
......@@ -91,13 +91,13 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
```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`)
super.onWorkStop(workInfo);
console.log(`onWorkStop value`);
}
}
```
......@@ -109,7 +109,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import workScheduler from '@ohos.resourceschedule.workScheduler'
import workScheduler from '@ohos.resourceschedule.workScheduler';
```
封装延迟任务注册、停止接口。
......@@ -124,13 +124,13 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
}
// 注册延迟任务
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 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
// 停止延迟任务
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 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
导入模块。
```ts
import { workAbility } from '@ohos/library'
import { workAbility } from '@ohos/library';
```
增加“升级”按钮,调用library封装的延迟任务注册接口,传入bundleName和abilityName,其中bilityName为WorkTest。
......@@ -163,7 +163,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
.height(40)
.fontSize(30)
.onClick(() => {
this.work.startWork('ohos.samples.workscheduler', 'WorkTest')
this.work.startWork('ohos.samples.workscheduler', 'WorkTest');
})
```
......@@ -171,7 +171,7 @@ WorkSchedulerExtensionAbility类拥有如下API接口,具体的API介绍详见
```ts
aboutToDisappear() {
this.work.stopWork('ohos.samples.workscheduler', 'WorkTest')
this.work.stopWork('ohos.samples.workscheduler', 'WorkTest');
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册