提交 8976b097 编写于 作者: W wangqing

描述修改

Signed-off-by: Nwangqing <wangqing136@huawei.com>
上级 6441fa65
...@@ -42,7 +42,8 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; ...@@ -42,7 +42,8 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
console.info("Request suspension delay will time out."); console.info("Request suspension delay will time out.");
}); });
var id = delayInfo.requestId;console.info("requestId is: " + id); var id = delayInfo.requestId;
console.info("requestId is: " + id);
``` ```
...@@ -50,9 +51,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; ...@@ -50,9 +51,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
```js ```js
backgroundTaskManager.getRemainingDelayTime(id).then( res => { backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
}).catch( err => { }).catch( err => {
console.log('promise => Operation failed. Cause: ' + err.data); console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data);
}); });
``` ```
...@@ -83,9 +84,9 @@ console.info("The actualDelayTime is: " + time); ...@@ -83,9 +84,9 @@ console.info("The actualDelayTime is: " + time);
// 获取应用程序进入挂起状态前的剩余时间 // 获取应用程序进入挂起状态前的剩余时间
backgroundTaskManager.getRemainingDelayTime(id).then( res => { backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
}).catch( err => { }).catch( err => {
console.log('promise => Operation failed. Cause: ' + err.data); console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data);
}); });
// 取消延迟挂起 // 取消延迟挂起
...@@ -172,16 +173,16 @@ ohos.permission.KEEP_BACKGROUND_RUNNING ...@@ -172,16 +173,16 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象 // 通过wantAgent模块的getWantAgent方法获取WantAgent对象
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
console.info("Operation succeeded"); console.info("Operation startBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
console.error("Operation failed Cause: " + err); console.error("Operation startBackgroundRunning failed Cause: " + err);
}); });
}); });
``` ```
...@@ -193,9 +194,9 @@ ohos.permission.KEEP_BACKGROUND_RUNNING ...@@ -193,9 +194,9 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info("Operation succeeded"); console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
console.error("Operation failed Cause: " + err); console.error("Operation stopBackgroundRunning failed Cause: " + err);
}); });
``` ```
...@@ -220,25 +221,25 @@ function startBackgroundRunning() { ...@@ -220,25 +221,25 @@ function startBackgroundRunning() {
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
// 通过wantAgent模块的getWantAgent方法获取WantAgent对象 // 通过wantAgent模块的getWantAgent方法获取WantAgent对象
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
console.info("Operation succeeded"); console.info("Operation startBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
console.error("Operation failed Cause: " + err); console.error("Operation startBackgroundRunning failed Cause: " + err);
}); });
}); });
} }
function stopBackgroundRunning() { function stopBackgroundRunning() {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info("Operation succeeded"); console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
console.error("Operation failed Cause: " + err); console.error("Operation stopBackgroundRunning failed Cause: " + err);
}); });
} }
......
...@@ -33,11 +33,17 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen ...@@ -33,11 +33,17 @@ requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspen
| [DelaySuspendInfo](#delaysuspendinfo) | 返回延迟挂起信息。 | | [DelaySuspendInfo](#delaysuspendinfo) | 返回延迟挂起信息。 |
**示例** **示例**
```js ```js
let myReason = 'test requestSuspendDelay'; let myReason = 'test requestSuspendDelay';
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => { let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspension delay will time out."); console.info("Request suspension delay will time out.");
}) })
var id = delayInfo.requestId;
var time = delayInfo.actualDelayTime;
console.info("The requestId is: " + id);
console.info("The actualDelayTime is: " + time);
``` ```
...@@ -61,9 +67,9 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;): ...@@ -61,9 +67,9 @@ getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;):
let id = 1; let id = 1;
backgroundTaskManager.getRemainingDelayTime(id, (err, res) => { backgroundTaskManager.getRemainingDelayTime(id, (err, res) => {
if(err.data === 0) { if(err.data === 0) {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
} else { } else {
console.log('promise => Operation failed. Cause: ' + err.data); console.log('callback => Operation getRemainingDelayTime failed. Cause: ' + err.data);
} }
}) })
``` ```
...@@ -91,9 +97,9 @@ getRemainingDelayTime(requestId: number): Promise&lt;number&gt; ...@@ -91,9 +97,9 @@ getRemainingDelayTime(requestId: number): Promise&lt;number&gt;
```js ```js
let id = 1; let id = 1;
backgroundTaskManager.getRemainingDelayTime(id).then( res => { backgroundTaskManager.getRemainingDelayTime(id).then( res => {
console.log('promise => Operation succeeded. Data: ' + JSON.stringify(res)); console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
}).catch( err => { }).catch( err => {
console.log('promise => Operation failed. Cause: ' + err.data); console.log('promise => Operation getRemainingDelayTime failed. Cause: ' + err.data);
}) })
``` ```
...@@ -143,9 +149,9 @@ import wantAgent from '@ohos.wantAgent'; ...@@ -143,9 +149,9 @@ import wantAgent from '@ohos.wantAgent';
function callback(err, data) { function callback(err, data) {
if (err) { if (err) {
console.error("Operation failed Cause: " + err); console.error("Operation startBackgroundRunning failed Cause: " + err);
} else { } else {
console.info("Operation succeeded"); console.info("Operation startBackgroundRunning succeeded");
} }
} }
...@@ -158,7 +164,7 @@ let wantAgentInfo = { ...@@ -158,7 +164,7 @@ let wantAgentInfo = {
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
...@@ -206,15 +212,15 @@ let wantAgentInfo = { ...@@ -206,15 +212,15 @@ let wantAgentInfo = {
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESET_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
console.info("Operation succeeded"); console.info("Operation startBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
console.error("Operation failed Cause: " + err); console.error("Operation startBackgroundRunning failed Cause: " + err);
}); });
}); });
...@@ -241,9 +247,9 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -241,9 +247,9 @@ import featureAbility from '@ohos.ability.featureAbility';
function callback(err, data) { function callback(err, data) {
if (err) { if (err) {
console.error("Operation failed Cause: " + err); console.error("Operation stopBackgroundRunning failed Cause: " + err);
} else { } else {
console.info("Operation succeeded"); console.info("Operation stopBackgroundRunning succeeded");
} }
} }
...@@ -275,9 +281,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; ...@@ -275,9 +281,9 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info("Operation succeeded"); console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => { }).catch((err) => {
console.error("Operation failed Cause: " + err); console.error("Operation stopBackgroundRunning failed Cause: " + err);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册