未验证 提交 51634731 编写于 作者: 朱天怡 提交者: Gitee

修改导入模块

Signed-off-by: N朱天怡 <zhutianyi2@huawei.com>
上级 20ee238b
...@@ -205,9 +205,9 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { ...@@ -205,9 +205,9 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
Stage模型示例: Stage模型示例:
```ts ```ts
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
function callback(err, data) { function callback(err, data) {
if (err) { if (err) {
...@@ -217,13 +217,13 @@ function callback(err, data) { ...@@ -217,13 +217,13 @@ function callback(err, data) {
} }
} }
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
let wantAgentInfo = { let wantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility" abilityName: "EntryAbility"
} }
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
...@@ -297,17 +297,17 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { ...@@ -297,17 +297,17 @@ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
Stage模型示例: Stage模型示例:
```ts ```ts
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
let wantAgentInfo = { let wantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility" abilityName: "EntryAbility"
} }
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
...@@ -365,7 +365,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callbac ...@@ -365,7 +365,7 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext(), callbac
Stage模型示例: Stage模型示例:
```ts ```ts
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
function callback(err, data) { function callback(err, data) {
...@@ -376,7 +376,7 @@ function callback(err, data) { ...@@ -376,7 +376,7 @@ function callback(err, data) {
} }
} }
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
backgroundTaskManager.stopBackgroundRunning(this.context, callback); backgroundTaskManager.stopBackgroundRunning(this.context, callback);
} }
...@@ -422,10 +422,10 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() ...@@ -422,10 +422,10 @@ backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(()
Stage模型示例: Stage模型示例:
```ts ```ts
import Ability from '@ohos.application.Ability'; import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.backgroundTaskManager'; import backgroundTaskManager from '@ohos.backgroundTaskManager';
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
console.info("Operation stopBackgroundRunning succeeded"); console.info("Operation stopBackgroundRunning succeeded");
......
...@@ -255,9 +255,9 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want ...@@ -255,9 +255,9 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
**示例** **示例**
```js ```js
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
function callback(error, data) { function callback(error, data) {
if (error) { if (error) {
...@@ -267,13 +267,13 @@ function callback(error, data) { ...@@ -267,13 +267,13 @@ function callback(error, data) {
} }
} }
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
let wantAgentInfo = { let wantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "MainAbility" abilityName: "EntryAbility"
} }
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
...@@ -281,14 +281,18 @@ export default class MainAbility extends Ability { ...@@ -281,14 +281,18 @@ export default class MainAbility extends Ability {
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { try {
try { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(this.context, try {
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback) backgroundTaskManager.startBackgroundRunning(this.context,
} catch (error) { backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
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}`);
}
} }
}; };
``` ```
...@@ -334,17 +338,17 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want ...@@ -334,17 +338,17 @@ startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: Want
**示例** **示例**
```js ```js
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
import wantAgent from '@ohos.wantAgent'; import wantAgent from '@ohos.app.ability.wantAgent';
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
let wantAgentInfo = { let wantAgentInfo = {
wants: [ wants: [
{ {
bundleName: "com.example.myapplication", bundleName: "com.example.myapplication",
abilityName: "MainAbility" abilityName: "EntryAbility"
} }
], ],
operationType: wantAgent.OperationType.START_ABILITY, operationType: wantAgent.OperationType.START_ABILITY,
...@@ -352,18 +356,22 @@ export default class MainAbility extends Ability { ...@@ -352,18 +356,22 @@ export default class MainAbility extends Ability {
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}; };
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { try {
try { wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
backgroundTaskManager.startBackgroundRunning(this.context, try {
backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => { backgroundTaskManager.startBackgroundRunning(this.context,
console.info("Operation startBackgroundRunning succeeded"); backgroundTaskManager.BackgroundMode.LOCATION, 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}`);
}); }
} }
}; };
``` ```
...@@ -400,7 +408,7 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): vo ...@@ -400,7 +408,7 @@ stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): vo
**示例** **示例**
```js ```js
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
function callback(error, data) { function callback(error, data) {
...@@ -411,7 +419,7 @@ function callback(error, data) { ...@@ -411,7 +419,7 @@ function callback(error, data) {
} }
} }
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
try { try {
backgroundTaskManager.stopBackgroundRunning(this.context, callback); backgroundTaskManager.stopBackgroundRunning(this.context, callback);
...@@ -461,10 +469,10 @@ stopBackgroundRunning(context: Context): Promise&lt;void&gt; ...@@ -461,10 +469,10 @@ stopBackgroundRunning(context: Context): Promise&lt;void&gt;
**示例** **示例**
```js ```js
import Ability from '@ohos.application.Ability' import UIAbility from '@ohos.app.ability.UIAbility';
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
export default class MainAbility extends Ability { export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) { onCreate(want, launchParam) {
try { try {
backgroundTaskManager.stopBackgroundRunning(this.context).then(() => { backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册