提交 c42aa374 编写于 作者: G Gloria

Update docs against 13792

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 8bc22295
...@@ -89,18 +89,22 @@ struct Index { ...@@ -89,18 +89,22 @@ struct Index {
}; };
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module. // Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { try {
try { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(this.context, try {
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { backgroundTaskManager.startBackgroundRunning(this.context,
console.info("Operation startBackgroundRunning succeeded"); backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
}).catch((err) => { console.info("Operation startBackgroundRunning succeeded");
console.error("Operation startBackgroundRunning failed Cause: " + err); }).catch((err) => {
}); console.error("Operation startBackgroundRunning failed Cause: " + err);
} 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}`);
}
} }
stopContinuousTask() { stopContinuousTask() {
...@@ -151,7 +155,7 @@ struct Index { ...@@ -151,7 +155,7 @@ struct Index {
```ts ```ts
import UIAbility from '@ohos.app.ability.UIAbility'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
const MSG_SEND_METHOD: string = 'CallSendMsg'; const MSG_SEND_METHOD: string = 'CallSendMsg';
...@@ -176,25 +180,29 @@ function startContinuousTask() { ...@@ -176,25 +180,29 @@ function startContinuousTask() {
}; };
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module. // Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { try {
try { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), try {
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { backgroundTaskManager.startBackgroundRunning(mContext,
console.info("Operation startBackgroundRunning succeeded"); backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
}).catch((error) => { 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}`); 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}`);
}); }
} }
function stopContinuousTask() { function stopContinuousTask() {
try { try {
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => { backgroundTaskManager.stopBackgroundRunning(mContext).then(() => {
console.info("Operation stopBackgroundRunning succeeded"); console.info("Operation stopBackgroundRunning succeeded");
}).catch((err) => { }).catch((error) => {
console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`); console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
}); });
} catch (error) { } catch (error) {
...@@ -312,7 +320,7 @@ If an application needs to interact with a continuous task in the background (fo ...@@ -312,7 +320,7 @@ If an application needs to interact with a continuous task in the background (fo
2. Call the APIs for requesting and canceling a continuous task in the Service ability. 2. Call the APIs for requesting and canceling a continuous task in the Service ability.
```js ```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
import wantAgent from '@ohos.app.ability.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
import rpc from "@ohos.rpc"; import rpc from "@ohos.rpc";
...@@ -335,18 +343,22 @@ function startContinuousTask() { ...@@ -335,18 +343,22 @@ function startContinuousTask() {
}; };
// Obtain the WantAgent object by using the getWantAgent API of the wantAgent module. // Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { try {
try { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(), try {
backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => { backgroundTaskManager.startBackgroundRunning(featureAbility.getContext(),
console.info("Operation startBackgroundRunning succeeded"); backgroundTaskManager.BackgroundMode.DATA_TRANSFER, wantAgentObj).then(() => {
}).catch((err) => { console.info("Operation startBackgroundRunning succeeded");
console.error("Operation startBackgroundRunning failed Cause: " + err); }).catch((err) => {
}); console.error("Operation startBackgroundRunning failed Cause: " + err);
} 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}`);
}
} }
function stopContinuousTask() { function stopContinuousTask() {
...@@ -396,7 +408,7 @@ class MyStub extends rpc.RemoteObject { ...@@ -396,7 +408,7 @@ class MyStub extends rpc.RemoteObject {
} }
export default { export default {
onStart(want) { onStart() {
console.info('ServiceAbility onStart'); console.info('ServiceAbility onStart');
mMyStub = new MyStub("ServiceAbility-test"); mMyStub = new MyStub("ServiceAbility-test");
// Call the API to start the task. // Call the API to start the task.
...@@ -416,7 +428,7 @@ export default { ...@@ -416,7 +428,7 @@ export default {
onDisconnect() { onDisconnect() {
console.info('ServiceAbility onDisconnect'); console.info('ServiceAbility onDisconnect');
}, },
onCommand(want, restart, startId) { onCommand(want, startId) {
console.info('ServiceAbility onCommand'); console.info('ServiceAbility onCommand');
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册