提交 cc6c582b 编写于 作者: Z zhangxin_T

modify code

Signed-off-by: Nzhangxin_T <zhangxin312@huawei.com>
上级 fe6cc89c
......@@ -8,7 +8,7 @@
应用中存在用户能够直观感受到的且需要一直在后台运行的业务时(如,后台播放音乐),可以使用长时任务机制。
对于系统特权应用,提供独立的能效资源申请接口。系统特权应用如果需要使用特定的系统资源,例如在被挂起期间仍然能够收到系统公共事件,可以使用能效资源申请接口。
对于系统特权应用,提供独立的能效资源申请接口。系统特权应用如果需要使用特定的系统资源,例如需要在被挂起期间仍然能够收到系统公共事件,可以使用能效资源申请接口。
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
......@@ -27,7 +27,7 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
后台应用申请延迟挂起。
延迟挂起时间一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000
延迟挂起时间一般情况下默认值为180000毫秒,低电量(依据系统低电量广播)时默认值为60000毫秒
**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
......@@ -49,9 +49,9 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspension delay will time out.");
})
var id = delayInfo.requestId;
var time = delayInfo.actualDelayTime;
let id = delayInfo.requestId;
let time = delayInfo.actualDelayTime;
console.info("The requestId is: " + id);
console.info("The actualDelayTime is: " + time);
```
......@@ -68,7 +68,7 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;):
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | --------------------------- | ---- | ---------------------------------------- |
| requestId | number | 是 | 延迟挂起的请求ID。 |
| requestId | number | 是 | 延迟挂起的请求ID。这个值通过调用requestSuspendDelay方法获取 |
| callback | AsyncCallback&lt;number&gt; | 是 | 指定的callback回调方法。用于返回应用程序进入挂起状态之前的剩余时间,以毫秒为单位。 |
**示例**
......@@ -96,7 +96,7 @@ getRemainingDelayTime(requestId: number): Promise&lt;number&gt;
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------- |
| requestId | number | 是 | 延迟挂起的请求ID。 |
| requestId | number | 是 | 延迟挂起的请求ID。这个值通过调用requestSuspendDelay方法获取 |
**返回值**
| 类型 | 说明 |
......@@ -125,7 +125,7 @@ cancelSuspendDelay(requestId: number): void
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------- |
| requestId | number | 是 | 延迟挂起的请求ID。 |
| requestId | number | 是 | 延迟挂起的请求ID。这个值通过调用requestSuspendDelay方法获取 |
**示例**
```js
......@@ -153,6 +153,9 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动长时任务的结果。 |
**示例**
FA模型示例:
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
......@@ -180,11 +183,48 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj, callback)
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
});
```
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent';
function callback(err, data) {
if (err) {
console.error("Operation startBackgroundRunning failed Cause: " + err);
} else {
console.info("Operation startBackgroundRunning succeeded");
}
}
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
});
}
};
```
## backgroundTaskManager.startBackgroundRunning<sup>8+</sup>
startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt;
......@@ -209,6 +249,9 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
| Promise\<void> | 使用Promise形式返回结果。 |
**示例**
FA模型示例:
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
......@@ -228,13 +271,45 @@ let wantAgentInfo = {
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => {
console.info("Operation startBackgroundRunning succeeded");
}).catch((err) => {
console.error("Operation startBackgroundRunning failed Cause: " + err);
});
});
```
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(this.context,
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => {
console.info("Operation startBackgroundRunning succeeded");
}).catch((err) => {
console.error("Operation startBackgroundRunning failed Cause: " + err);
});
});
}
};
```
## backgroundTaskManager.stopBackgroundRunning<sup>8+</sup>
......@@ -252,6 +327,9 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): vo
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动长时任务的结果。 |
**示例**
FA模型示例:
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
......@@ -268,6 +346,27 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callbac
```
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import backgroundTaskManager from '@ohos.backgroundTaskManager';
function callback(err, data) {
if (err) {
console.error("Operation stopBackgroundRunning failed Cause: " + err);
} else {
console.info("Operation stopBackgroundRunning succeeded");
}
}
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
backgroundTaskManager.stopBackgroundRunning(this.context, callback);
}
};
```
## backgroundTaskManager.stopBackgroundRunning<sup>8+</sup>
stopBackgroundRunning(context: Context): Promise&lt;void&gt;
......@@ -287,6 +386,9 @@ stopBackgroundRunning(context: Context): Promise&lt;void&gt;
| Promise\<void> | 使用Promise形式返回结果。 |
**示例**
FA模型示例:
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
......@@ -299,11 +401,30 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(()
```
Stage模型示例:
```ts
import Ability from '@ohos.application.Ability'
import backgroundTaskManager from '@ohos.backgroundTaskManager';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => {
console.error("Operation stopBackgroundRunning failed Cause: " + err);
});
}
};
```
## backgroundTaskManager.applyEfficiencyResources<sup>9+</sup>
applyEfficiencyResources(request: [EfficiencyResourcesRequest](#efficiencyresourcesrequest9)): boolean
向系统申请能效资源,使用boolean形式返回结果。
向系统申请或释放能效资源,使用boolean形式返回结果。
通过EfficiencyResourcesRequest参数中的isApply变量,指定是申请还是释放。
应用使用此接口前,需要向应用中心申请获得相应特权。
进程和它所属的应用可以同时申请某一类资源,例如CPU资源,但是应用释放资源的时候会将进程的资源一起释放。
**系统能力**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
......@@ -343,6 +464,7 @@ console.info("result of applyEfficiencyResources is: " + res)
resetAllEfficiencyResources(): void
释放所有已经申请的资源。
应用使用此接口前,需要向应用中心申请获得相应特权。
**系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
......@@ -353,7 +475,7 @@ resetAllEfficiencyResources(): void
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
backgroundTaskManager.backgroundTaskManager.resetAllEfficiencyResources();
backgroundTaskManager.resetAllEfficiencyResources();
```
......
......@@ -23,7 +23,7 @@
## 导入模块
```
```js
import bundleState from '@ohos.bundleState'
```
......@@ -31,7 +31,7 @@ import bundleState from '@ohos.bundleState'
isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,使用Callback形式返回。
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,查询其他应用空闲状态,需要申请权限:ohos.permission.BUNDLE_ACTIVE_INFO,使用Callback形式返回。
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
......@@ -44,7 +44,7 @@ isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
**示例**
```
```js
bundleState.isIdleState("com.ohos.camera", (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
......@@ -58,7 +58,7 @@ isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
isIdleState(bundleName: string): Promise&lt;boolean&gt;
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,使用Promise形式返回。
判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,查询其他应用空闲状态,需要申请权限:ohos.permission.BUNDLE_ACTIVE_INFO,使用Promise形式返回。
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
......@@ -237,7 +237,7 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
**示例**
```js
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
bundleState.queryBundleStateInfoByInterval(bundleState.IntervalType.BY_OPTIMIZED, 0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} else {
......@@ -279,7 +279,7 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
**示例**
```js
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
bundleState.queryBundleStateInfoByInterval(bundleState.IntervalType.BY_OPTIMIZED, 0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
......
......@@ -203,7 +203,7 @@ startBackgroundRunning(id: number, request: NotificationRequest, callback: Async
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| id | number | 是 | 长时任务通知id号 |
| request | NotificationRequest | 是 | 通知参数,用于显示通知栏的信息 |
| request | [NotificationRequest](js-apis-notification.md#notificationrequest) | 是 | 通知参数,用于显示通知栏的信息 |
| callback | AsyncCallback&lt;void&gt; | 是 | callback形式返回启动长时任务的结果 |
**示例**
......@@ -267,7 +267,7 @@ startBackgroundRunning(id: number, request: NotificationRequest): Promise&lt;voi
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| id | number | 是 | 长时任务通知id号 |
| request | NotificationRequest | 是 | 通知参数,用于显示通知栏的信息 |
| request | [NotificationRequest](js-apis-notification.md#notificationrequest) | 是 | 通知参数,用于显示通知栏的信息 |
**返回值:**
......
......@@ -10,7 +10,7 @@
## 导入模块
```
```js
import reminderAgent from'@ohos.reminderAgent';
```
......@@ -453,9 +453,9 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reminderType | ReminderType | 是 | 指明提醒类型。 |
| actionButton | [ActionButton?,&nbsp;ActionButton?] | 否 | 弹出的提醒通知栏中显示的按钮(参数可选,支持0/1/2个按钮)。 |
| wantAgent | WantAgent | 否 | 点击通知后需要跳转的目标ability信息。 |
| maxScreenWantAgent | MaxScreenWantAgent | 否 | 提醒到达时跳转的目标包。如果设备正在使用中,则弹出一个通知框。 |
| actionButton | [ActionButton](#actionbutton) | 否 | 弹出的提醒通知栏中显示的按钮(参数可选,支持0/1/2个按钮)。 |
| wantAgent | [WantAgent](#wantagent) | 否 | 点击通知后需要跳转的目标ability信息。 |
| maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | 否 | 提醒到达时跳转的目标包。如果设备正在使用中,则弹出一个通知框。 |
| ringDuration | number | 否 | 指明响铃时长。 |
| snoozeTimes | number | 否 | 指明延迟提醒次数。 |
| timeInterval | number | 否 | 执行延迟提醒间隔。 |
......
......@@ -53,7 +53,7 @@ startWork(work: WorkInfo): boolean
mykey3: 1.5
}
}
var res = workScheduler.startWork(workInfo);
let res = workScheduler.startWork(workInfo);
console.info(`workschedulerLog res: ${res}`);
```
......@@ -94,7 +94,7 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean
mykey3: 1.5
}
}
var res = workScheduler.stopWork(workInfo, false);
let res = workScheduler.stopWork(workInfo, false);
console.info(`workschedulerLog res: ${res}`);
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册