提交 ad0d714a 编写于 作者: H hunili

arkts 指导文档示例代码规范化整改

issue: https://gitee.com/openharmony/docs/issues/I7WC28Signed-off-by: Nhunili <lihucheng2@huawei.com>
上级 72b922b9
......@@ -60,10 +60,10 @@
```json
{
"module": {
...
// ...
"abilities": [
{
...
// ...
"continuable": true,
}
]
......@@ -85,19 +85,23 @@
示例如下:
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
onContinue(wantParam : {[key: string]: Object}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`) //准备迁移数据
export default class EntryAbility extends UIAbility {
onContinue(wantParam: Record<string, Object>) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`) // 准备迁移数据
let continueInput = '迁移的数据';
if (continueInput) {
// 将要迁移的数据保存在wantParam的自定义字段(如:data)中;
wantParam["data"] = continueInput
console.info(`onContinue input = ${wantParam["input"]}`);
return AbilityConstant.OnContinueResult.AGREE
}
```
wantParam["data"] = continueInput;
}
console.info(`onContinue input = ${wantParam["data"]}`);
return AbilityConstant.OnContinueResult.AGREE;
}
}
```
5.在Stage模型中,应用在不同启动模式下将调用不同的接口,以恢复数据、加载界面。
......@@ -115,17 +119,20 @@ onContinue(wantParam : {[key: string]: Object}) {
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onCreate(want, launchParam) {
storage : LocalStorage = new LocalStorage();
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
console.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// 将上述的保存的数据取出恢复
let continueInput = want.parameters.data
let continueInput = '';
if (want.parameters != undefined) {
continueInput = JSON.stringify(want.parameters.data);
console.info(`continue input ${continueInput}`)
}
// 将数据显示当前页面
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
......@@ -135,15 +142,21 @@ onContinue(wantParam : {[key: string]: Object}) {
- 在onNewWant中判断迁移场景,恢复数据,并触发页面恢复
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onNewWant(want, launchParam) {
storage : LocalStorage = new LocalStorage();
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
console.info(`EntryAbility onNewWant ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// get user data from want params
let continueInput = want.parameters.data
console.info(`continue input ${continueInput}`)
this.storage = new LocalStorage();
let continueInput = '';
if (want.parameters != undefined) {
continueInput = JSON.stringify(want.parameters.data);
console.info(`continue input ${continueInput}`);
}
this.context.restoreWindowStage(this.storage);
}
}
......@@ -171,12 +184,17 @@ onContinue(wantParam : {[key: string]: Object}) {
```ts
// EntryAbility.ets
onCreate(want, launchParam) {
...
this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => {
console.info('setMissionContinueState ACTIVE result: ', JSON.stringify(result));
};
...
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// ...
this.context.setMissionContinueState(AbilityConstant.ContinueState.INACTIVE, (result) => {
console.info(`setMissionContinueState: ${JSON.stringify(result)}`);
});
// ...
}
}
```
......@@ -184,16 +202,21 @@ onCreate(want, launchParam) {
```ts
// PageName.ets
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import common from '@ohos.app.ability.common'
@Entry
@Component
struct PageName {
Build() {
...
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
}
...
// ...
onPageShow(){
// 进入该页面时,将应用设置为可迁移状态
this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => {
console.info('setMissionContinueState ACTIVE result: ', JSON.stringify(result));
};
});
}
}
```
......@@ -201,16 +224,25 @@ struct PageName {
在某个组件的触发事件中设置应用迁移能力。如下例中,使用 **Button** 组件的 **onClick** 事件,触发迁移能力的改变。
```ts
// xxx.ets
Button(){
...
}
.onClick(()=>{
// PageName.ets
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import common from '@ohos.app.ability.common'
@Entry
@Component
struct PageName {
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
Button() {
//...
}.onClick(()=>{
//点击该按钮时,将应用设置为可迁移状态
this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => {
console.info('setMissionContinueState ACTIVE result: ', JSON.stringify(result));
};
})
});
})
}
}
```
**保证迁移连续性**
......@@ -219,24 +251,28 @@ Button(){
```ts
// EntryAbility.ets
onCreate(want, launchparam) {
...
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
// ...
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// ...
// 调用原因为迁移时,设置状态为可迁移,应对冷启动情况
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => {
console.info('setMissionContinueState ACTIVE result: ', JSON.stringify(result));
};
this.context.setMissionContinueState(AbilityConstant.ContinueState.INACTIVE, (result) => {
console.info(`setMissionContinueState: ${JSON.stringify(result)}`);
});
}
}
onNewWant(want, launchparam) {
...
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// ...
// 调用原因为迁移时,设置状态为可迁移,应对热启动情况
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => {
console.info('setMissionContinueState ACTIVE result: ', JSON.stringify(result));
};
});
}
}
// ...
}
```
......@@ -251,18 +287,29 @@ onNewWant(want, launchparam) {
- 示例:应用迁移不需要自动迁移页面栈信息
```ts
// EntryAbility.ets
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import wantConstant from '@ohos.app.ability.wantConstant';
onContinue(wantParam : {[key: string]: Object}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
// ...
onContinue(wantParam: Record<string, Object>) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`);
wantParam[wantConstant.Params.SUPPORT_CONTINUE_PAGE_STACK_KEY] = false;
return AbilityConstant.OnContinueResult.AGREE;
}
onWindowStageRestore(windowStage) {
// ...
onWindowStageRestore(windowStage: window.WindowStage) {
// 若不需要自动迁移页面栈信息,则需要在此处设置应用迁移后进入的页面
windowStage.setUIContent(this.contex, "pages/index", null);
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
console.info('Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
console.info('Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
}
```
......@@ -274,13 +321,17 @@ onNewWant(want, launchparam) {
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import wantConstant from '@ohos.app.ability.wantConstant';
onContinue(wantParam : {[key: string]: Object}) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`)
export default class EntryAbility extends UIAbility {
// ...
onContinue(wantParam: Record<string, Object>) {
console.info(`onContinue version = ${wantParam.version}, targetDevice: ${wantParam.targetDevice}`);
wantParam[wantConstant.Params.SUPPORT_CONTINUE_SOURCE_EXIT_KEY] = false;
return AbilityConstant.OnContinueResult.AGREE;
}
// ...
}
```
## 验证指导
......
......@@ -64,7 +64,7 @@
try{
dmClass = deviceManager.createDeviceManager('ohos.samples.demo');
} catch(err) {
console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message);
console.error("createDeviceManager err: " + JSON.stringify(err));
}
}
function getRemoteDeviceId() {
......@@ -81,6 +81,7 @@
return list[0].networkId;
} else {
console.info('getRemoteDeviceId err: dmClass is null');
return;
}
}
```
......@@ -88,7 +89,9 @@
4. 设置目标组件参数,调用[`startAbility()`](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstartability)接口,启动UIAbility或ServiceExtensionAbility。
```ts
let want = {
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
let want: Want = {
deviceId: getRemoteDeviceId(),
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
......@@ -96,16 +99,19 @@
}
// context为发起端UIAbility的AbilityContext
this.context.startAbility(want).then(() => {
...
}).catch((err) => {
...
// ...
}).catch((err: BusinessError) => {
// ...
console.error("startAbility err: " + JSON.stringify(err));
})
```
5. 当设备A发起端应用不需要设备B上的ServiceExtensionAbility时,可调用[stopServiceExtensionAbility](../reference/apis/js-apis-inner-application-uiAbilityContext.md#uiabilitycontextstopserviceextensionability)接口退出。(该接口不支持UIAbility的退出,UIAbility由用户手动通过任务管理退出)
```ts
let want = {
import Want from '@ohos.app.ability.Want';
import { BusinessError } from '@ohos.base';
let want: Want = {
deviceId: getRemoteDeviceId(),
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
......@@ -114,7 +120,7 @@
// 退出由startAbility接口启动的ServiceExtensionAbility
this.context.stopServiceExtensionAbility(want).then(() => {
console.info("stop service extension ability success")
}).catch((err) => {
}).catch((err: BusinessError) => {
console.info("stop service extension ability err is " + JSON.stringify(err))
})
```
......@@ -144,7 +150,19 @@
3. 在发起端设置目标组件参数,调用startAbilityForResult()接口启动目标端UIAbility,异步回调中的data用于接收目标端UIAbility停止自身后返回给调用方UIAbility的信息。getRemoteDeviceId方法参照[通过跨设备启动uiability和serviceextensionability组件实现多端协同无返回数据](#通过跨设备启动uiability和serviceextensionability组件实现多端协同无返回数据)
```ts
let want = {
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
@Entry
@Component
struct PageName {
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
Button('StartAbilityForResult')
.onClick(()=>{
let want: Want = {
deviceId: getRemoteDeviceId(),
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
......@@ -152,47 +170,87 @@
}
// context为发起端UIAbility的AbilityContext
this.context.startAbilityForResult(want).then((data) => {
...
}).catch((err) => {
...
// ...
}).catch((error: BusinessError) => {
console.info("startAbilityForResult err: " + JSON.stringify(error));
})
}
)
}
}
```
4. 在目标端UIAbility任务完成后,调用terminateSelfWithResult()方法,将数据返回给发起端的UIAbility。
```ts
import { BusinessError } from '@ohos.base';
import common from '@ohos.app.ability.common';
@Entry
@Component
struct PageName {
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
Button('terminateSelfWithResult')
.onClick(()=>{
const RESULT_CODE: number = 1001;
let abilityResult = {
// context为目标端UIAbility的AbilityContext
this.context.terminateSelfWithResult(
{
resultCode: RESULT_CODE,
want: {
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
moduleName: 'module1',
},
}
// context为目标端UIAbility的AbilityContext
this.context.terminateSelfWithResult(abilityResult, (err) => {
...
},
(err: BusinessError) => {
// ...
console.info("terminateSelfWithResult err: " + JSON.stringify(err));
});
}
// ...
)
}
}
```
5. 发起端UIAbility接收到目标端UIAbility返回的信息,对其进行处理。
```ts
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
import Want from '@ohos.app.ability.Want';
@Entry
@Component
struct PageName {
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
Button('StartAbilityForResult')
.onClick(()=>{
let want: Want = {
deviceId: getRemoteDeviceId(),
bundleName: 'com.example.myapplication',
abilityName: 'FuncAbility',
moduleName: 'module1', // moduleName非必选
}
const RESULT_CODE: number = 1001;
...
// ...
// context为调用方UIAbility的UIAbilityContext
this.context.startAbilityForResult(want).then((data) => {
if (data?.resultCode === RESULT_CODE) {
// 解析目标端UIAbility返回的信息
let info = data.want?.parameters?.info
...
let info = data.want?.parameters?.info;
// ...
}
}).catch((err) => {
...
}).catch((error: BusinessError) => {
// ...
})
}
)
}
}
```
......@@ -229,14 +287,26 @@
```ts
import rpc from '@ohos.rpc';
import Want from '@ohos.app.ability.Want';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
@Entry
@Component
struct PageName {
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
Button('connectServiceExtensionAbility')
.onClick(()=>{
const REQUEST_CODE = 99;
let want = {
let want: Want = {
"deviceId": getRemoteDeviceId(),
"bundleName": "com.example.myapplication",
"abilityName": "ServiceExtAbility"
};
let options = {
// 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入
let connectionId = this.context.connectServiceExtensionAbility(want,
{
onConnect(elementName, remote) {
console.info('onConnect callback');
if (remote === null) {
......@@ -248,17 +318,16 @@
let reply = new rpc.MessageParcel();
data.writeInt(1);
data.writeInt(99); // 开发者可发送data到目标端应用进行相应操作
// @param code 表示客户端发送的服务请求代码。
// @param data 表示客户端发送的{@link MessageParcel}对象。
// @param reply 表示远程服务发送的响应消息对象。
// @param options 指示操作是同步的还是异步的。
//
// @return 如果操作成功返回{@code true}; 否则返回 {@code false}。
remote.sendRequest(REQUEST_CODE, data, reply, option).then((ret) => {
remote.sendRequest(REQUEST_CODE, data, reply, option).then((ret: rpc.SendRequestResult) => {
let msg = reply.readInt(); // 在成功连接的情况下,会收到来自目标端返回的信息(100)
console.info(`sendRequest ret:${ret} msg:${msg}`);
}).catch((error) => {
}).catch((error: BusinessError) => {
console.info('sendRequest failed');
});
},
......@@ -268,9 +337,10 @@
onFailed(code) {
console.info('onFailed callback');
}
});
})
}
}
// 建立连接后返回的Id需要保存下来,在解绑服务时需要作为参数传入
let connectionId = this.context.connectServiceExtensionAbility(want, options);
```
getRemoteDeviceId方法参照[通过跨设备启动uiability和serviceextensionability组件实现多端协同无返回数据](#通过跨设备启动uiability和serviceextensionability组件实现多端协同无返回数据)。
......@@ -278,12 +348,25 @@
5. 断开连接。调用disconnectServiceExtensionAbility()断开与后台服务的连接。
```ts
let connectionId = 1 // 在通过connectServiceExtensionAbility绑定服务时返回的Id
this.context.disconnectServiceExtensionAbility(connectionId).then((data) => {
import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
@Entry
@Component
struct PageName {
private context = getContext(this) as common.UIAbilityContext;
build() {
// ...
Button('disconnectServiceExtensionAbility')
.onClick(()=>{
let connectionId: number = 1 // 在通过connectServiceExtensionAbility绑定服务时返回的Id
this.context.disconnectServiceExtensionAbility(connectionId).then(() => {
console.info('disconnectServiceExtensionAbility success');
}).catch((error) => {
}).catch((error: BusinessError) => {
console.error('disconnectServiceExtensionAbility failed');
})
})
}
}
```
......@@ -342,29 +425,30 @@
2. 导入UIAbility模块。
```ts
import Ability from '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
```
3. 定义约定的序列化数据。
调用端及被调用端发送接收的数据格式需协商一致,如下示例约定数据由number和string组成。
```ts
import rpc from '@ohos.rpc'
export default class MyParcelable {
num: number = 0;
str: string = "";
constructor(num, string) {
constructor(num: number, string: string) {
this.num = num;
this.str = string;
}
marshalling(messageSequence) {
marshalling(messageSequence: rpc.MessageParcel) {
messageSequence.writeInt(this.num);
messageSequence.writeString(this.str);
return true;
}
unmarshalling(messageSequence) {
unmarshalling(messageSequence: rpc.MessageParcel) {
this.num = messageSequence.readInt();
this.str = messageSequence.readString();
return true;
......@@ -375,24 +459,28 @@
如下示例在Ability的onCreate注册MSG_SEND_METHOD监听,在onDestroy取消监听,收到序列化数据后作相应处理并返回。应用开发者根据实际业务需要做相应处理。
```ts
import rpc from '@ohos.rpc';
import Want from '@ohos.app.ability.Want';
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
const TAG: string = '[CalleeAbility]';
const MSG_SEND_METHOD: string = 'CallSendMsg';
function sendMsgCallback(data) {
function sendMsgCallback(data: rpc.MessageSequence): MyParcelable {
console.info('CalleeSortFunc called');
// 获取Caller发送的序列化数据
let receivedData = new MyParcelable(0, '');
let receivedData: MyParcelable = new MyParcelable(0, '');
data.readParcelable(receivedData);
console.info(`receiveData[${receivedData.num}, ${receivedData.str}]`);
// 作相应处理
// 返回序列化数据result给Caller
return new MyParcelable(receivedData.num + 1, `send ${receivedData.str} succeed`);
return new MyParcelable(Number(receivedData.num) + 1, `send ${receivedData.str} succeed`);
}
export default class CalleeAbility extends Ability {
onCreate(want, launchParam) {
export default class CalleeAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
try {
this.callee.on(MSG_SEND_METHOD, sendMsgCallback);
} catch (error) {
......@@ -414,16 +502,20 @@
1. 导入UIAbility模块。
```ts
import Ability from '@ohos.app.ability.UIAbility';
import UIAbility from '@ohos.app.ability.UIAbility';
```
2. 获取Caller通信接口。
Ability的context属性实现了startAbilityByCall方法,用于获取指定通用组件的Caller通信接口。如下示例通过this.context获取Ability实例的context属性,使用startAbilityByCall拉起Callee被调用端并获取Caller通信接口,注册Caller的onRelease和onRemoteStateChange监听。应用开发者根据实际业务需要做相应处理。
```ts
import UIAbility, { Caller } from '@ohos.app.ability.UIAbility';
import { BusinessError } from '@ohos.base';
export default class EntryAbility extends UIAbility {
// ...
async onButtonGetRemoteCaller() {
var caller = undefined;
var context = this.context;
let caller: Caller | undefined;
let context = this.context;
context.startAbilityByCall({
deviceId: getRemoteDeviceId(),
......@@ -447,10 +539,12 @@
console.info('Caller.onRemoteStateChange catch error, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}');
}
}
}).catch((error) => {
}).catch((error: BusinessError) => {
console.error(`get remote caller failed with ${error}`);
})
}
// ...
}
```
getRemoteDeviceId方法参照[通过跨设备启动uiability和serviceextensionability组件实现多端协同无返回数据](#通过跨设备启动uiability和serviceextensionability组件实现多端协同无返回数据)。
......@@ -459,49 +553,72 @@
1. 向被调用端发送Parcelable数据有两种方式,一种是不带返回值,一种是获取被调用端返回的数据,method以及序列化数据需要与被调用端协商一致。如下示例调用Call接口,向Callee被调用端发送数据。
```ts
import UIAbility, { Caller } from '@ohos.app.ability.UIAbility';
import { BusinessError } from '@ohos.base';
const MSG_SEND_METHOD: string = 'CallSendMsg';
export default class EntryAbility extends UIAbility {
// ...
caller: Caller | undefined;
async onButtonCall() {
try {
let msg = new MyParcelable(1, 'origin_Msg');
let msg: MyParcelable = new MyParcelable(1, 'origin_Msg');
if (this.caller) {
await this.caller.call(MSG_SEND_METHOD, msg);
}
} catch (error) {
console.info(`caller call failed with ${error}`);
}
}
// ...
}
```
2. 如下示例调用CallWithResult接口,向Callee被调用端发送待处理的数据originMsg,并将’CallSendMsg’方法处理完毕的数据赋值给backMsg。
```ts
import UIAbility, { Caller } from '@ohos.app.ability.UIAbility';
import rpc from '@ohos.rpc';
const MSG_SEND_METHOD: string = 'CallSendMsg';
let originMsg: string = '';
let backMsg: string = '';
async onButtonCallWithResult(originMsg, backMsg) {
export default class EntryAbility extends UIAbility {
// ...
caller: Caller | undefined;
async onButtonCallWithResult(originMsg: string, backMsg: string) {
try {
let msg = new MyParcelable(1, originMsg);
let msg: MyParcelable = new MyParcelable(1, originMsg);
if (this.caller) {
const data = await this.caller.callWithResult(MSG_SEND_METHOD, msg);
console.info('caller callWithResult succeed');
let result = new MyParcelable(0, '');
let result: MyParcelable = new MyParcelable(0, '');
data.readParcelable(result);
backMsg(result.str);
backMsg = result.str;
console.info(`caller result is [${result.num}, ${result.str}]`);
}
} catch (error) {
console.info(`caller callWithResult failed with ${error}`);
}
}
// ...
}
```
6. 释放Caller通信接口。
Caller不再使用后,应用开发者可以通过release接口释放Caller。
```ts
import UIAbility, { Caller } from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
caller: Caller | undefined;
releaseCall() {
try {
if (this.caller) {
this.caller.release();
this.caller = undefined
this.caller = undefined;
}
console.info('caller release succeed');
} catch (error) {
console.info(`caller release failed with ${error}`);
}
}
}
```
......@@ -43,7 +43,8 @@ register(callback: AsyncCallback\<number>): void;
**示例:**
```ts
let token = -1;
import continuationManager from '@ohos.continuation.continuationManager'
let token: number = -1;
continuationManager.register((err, data) => {
if (err.code != 0) {
console.error('register failed, cause: ' + JSON.stringify(err));
......@@ -85,11 +86,13 @@ register(options: ContinuationExtraParams, callback: AsyncCallback\<number>): vo
**示例:**
```ts
let token = -1;
let continuationExtraParams = {
import continuationManager from '@ohos.continuation.continuationManager'
let token: number = -1;
continuationManager.register(
{
deviceType: ["00E"]
};
continuationManager.register(continuationExtraParams, (err, data) => {
},
(err, data) => {
if (err.code != 0) {
console.error('register failed, cause: ' + JSON.stringify(err));
return;
......@@ -135,16 +138,14 @@ register(options?: ContinuationExtraParams): Promise\<number>;
**示例:**
```ts
let token = -1;
let continuationExtraParams = {
deviceType: ["00E"]
};
continuationManager.register(continuationExtraParams)
.then((data) => {
import continuationManager from '@ohos.continuation.continuationManager'
import { BusinessError } from '@ohos.base';
let token: number = -1;
continuationManager.register(
{ deviceType: ["00E"] }).then((data) => {
console.info('register finished, ' + JSON.stringify(data));
token = data;
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('register failed, cause: ' + JSON.stringify(err));
});
```
......@@ -177,7 +178,8 @@ registerContinuation(callback: AsyncCallback\<number>): void;
**示例:**
```ts
let token = -1;
import continuationManager from '@ohos.continuation.continuationManager'
let token: number = -1;
try {
continuationManager.registerContinuation((err, data) => {
if (err.code != 0) {
......@@ -221,12 +223,14 @@ registerContinuation(options: ContinuationExtraParams, callback: AsyncCallback\<
**示例:**
```ts
let token = -1;
let continuationExtraParams = {
deviceType: ["00E"]
};
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = -1;
try {
continuationManager.registerContinuation(continuationExtraParams, (err, data) => {
continuationManager.registerContinuation(
{
deviceType: ["00E"]
},
(err, data) => {
if (err.code != 0) {
console.error('registerContinuation failed, cause: ' + JSON.stringify(err));
return;
......@@ -273,17 +277,17 @@ registerContinuation(options?: ContinuationExtraParams): Promise\<number>;
**示例:**
```ts
let token = -1;
let continuationExtraParams = {
deviceType: ["00E"]
};
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = -1;
try {
continuationManager.register(continuationExtraParams)
.then((data) => {
continuationManager.register(
{
deviceType: ["00E"]
}).then((data) => {
console.info('registerContinuation finished, ' + JSON.stringify(data));
token = data;
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('registerContinuation failed, cause: ' + JSON.stringify(err));
});
} catch (err) {
......@@ -324,6 +328,7 @@ on(type: "deviceConnect", callback: Callback\<ContinuationResult>): void;
**示例:**
```ts
import continuationManager from '@ohos.continuation.continuationManager';
continuationManager.on("deviceConnect", (data) => {
console.info('onDeviceConnect deviceId: ' + JSON.stringify(data.id));
console.info('onDeviceConnect deviceType: ' + JSON.stringify(data.type));
......@@ -363,6 +368,7 @@ on(type: "deviceDisconnect", callback: Callback\<string>): void;
**示例:**
```ts
import continuationManager from '@ohos.continuation.continuationManager';
continuationManager.on("deviceDisconnect", (data) => {
console.info('onDeviceDisconnect deviceId: ' + JSON.stringify(data));
});
......@@ -400,6 +406,7 @@ off(type: "deviceConnect", callback?: Callback\<ContinuationResult>): void;
**示例:**
```ts
import continuationManager from '@ohos.continuation.continuationManager';
continuationManager.off("deviceConnect", (data) => {
console.info('onDeviceConnect deviceId: ' + JSON.stringify(data.id));
console.info('onDeviceConnect deviceType: ' + JSON.stringify(data.type));
......@@ -439,6 +446,7 @@ off(type: "deviceDisconnect", callback?: Callback\<string>): void;
**示例:**
```ts
import continuationManager from '@ohos.continuation.continuationManager';
continuationManager.off("deviceDisconnect", (data) => {
console.info('onDeviceDisconnect deviceId: ' + JSON.stringify(data));
});
......@@ -475,7 +483,8 @@ on(type: "deviceSelected", token: number, callback: Callback\<Array\<Continuatio
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
try {
continuationManager.on("deviceSelected", token, (data) => {
console.info('onDeviceSelected len: ' + data.length);
......@@ -521,7 +530,8 @@ on(type: "deviceUnselected", token: number, callback: Callback\<Array\<Continuat
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
try {
continuationManager.on("deviceUnselected", token, (data) => {
console.info('onDeviceUnselected len: ' + data.length);
......@@ -567,7 +577,8 @@ off(type: "deviceSelected", token: number): void;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
try {
continuationManager.off("deviceSelected", token);
} catch (err) {
......@@ -605,7 +616,8 @@ off(type: "deviceUnselected", token: number): void;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
try {
continuationManager.off("deviceUnselected", token);
} catch (err) {
......@@ -646,7 +658,8 @@ startDeviceManager(token: number, callback: AsyncCallback\<void>): void;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
continuationManager.startDeviceManager(token, (err, data) => {
if (err.code != 0) {
console.error('startDeviceManager failed, cause: ' + JSON.stringify(err));
......@@ -690,11 +703,14 @@ startDeviceManager(token: number, options: ContinuationExtraParams, callback: As
**示例:**
```ts
let token = 1;
let continuationExtraParams = {
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
continuationManager.startDeviceManager(
token,
{
deviceType: ["00E"]
};
continuationManager.startDeviceManager(token, continuationExtraParams, (err, data) => {
},
(err, data) => {
if (err.code != 0) {
console.error('startDeviceManager failed, cause: ' + JSON.stringify(err));
return;
......@@ -742,15 +758,16 @@ startDeviceManager(token: number, options?: ContinuationExtraParams): Promise\<v
**示例:**
```ts
let token = 1;
let continuationExtraParams = {
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = -1;
continuationManager.startDeviceManager(
token,
{
deviceType: ["00E"]
};
continuationManager.startDeviceManager(token, continuationExtraParams)
.then((data) => {
}).then((data) => {
console.info('startDeviceManager finished, ' + JSON.stringify(data));
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('startDeviceManager failed, cause: ' + JSON.stringify(err));
});
```
......@@ -784,7 +801,8 @@ startContinuationDeviceManager(token: number, callback: AsyncCallback\<void>): v
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = -1;
try {
continuationManager.startContinuationDeviceManager(token, (err, data) => {
if (err.code != 0) {
......@@ -828,12 +846,15 @@ startContinuationDeviceManager(token: number, options: ContinuationExtraParams,
**示例:**
```ts
let token = 1;
let continuationExtraParams = {
deviceType: ["00E"]
};
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = -1;
try {
continuationManager.startContinuationDeviceManager(token, continuationExtraParams, (err, data) => {
continuationManager.startContinuationDeviceManager(
token,
{
deviceType: ["00E"]
},
(err, data) => {
if (err.code != 0) {
console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
return;
......@@ -880,16 +901,17 @@ startContinuationDeviceManager(token: number, options?: ContinuationExtraParams)
**示例:**
```ts
let token = 1;
let continuationExtraParams = {
deviceType: ["00E"]
};
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = -1;
try {
continuationManager.startContinuationDeviceManager(token, continuationExtraParams)
.then((data) => {
continuationManager.startContinuationDeviceManager(
token,
{
deviceType: ["00E"]
}).then((data) => {
console.info('startContinuationDeviceManager finished, ' + JSON.stringify(data));
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
});
} catch (err) {
......@@ -932,7 +954,8 @@ updateConnectStatus(token: number, deviceId: string, status: DeviceConnectState,
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = -1;
let deviceId: string = "test deviceId";
continuationManager.updateConnectStatus(token, deviceId, continuationManager.DeviceConnectState.CONNECTED, (err, data) => {
if (err.code != 0) {
......@@ -983,13 +1006,15 @@ updateConnectStatus(token: number, deviceId: string, status: DeviceConnectState)
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = 1;
let deviceId: string = "test deviceId";
continuationManager.updateConnectStatus(token, deviceId, continuationManager.DeviceConnectState.CONNECTED)
.then((data) => {
console.info('updateConnectStatus finished, ' + JSON.stringify(data));
})
.catch((err) => {
.catch((err: BusinessError) => {
console.error('updateConnectStatus failed, cause: ' + JSON.stringify(err));
});
```
......@@ -1025,7 +1050,8 @@ updateContinuationState(token: number, deviceId: string, status: DeviceConnectSt
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
let deviceId: string = "test deviceId";
try {
continuationManager.updateContinuationState(token, deviceId, continuationManager.DeviceConnectState.CONNECTED, (err, data) => {
......@@ -1076,14 +1102,16 @@ updateContinuationState(token: number, deviceId: string, status: DeviceConnectSt
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = 1;
let deviceId: string = "test deviceId";
try {
continuationManager.updateContinuationState(token, deviceId, continuationManager.DeviceConnectState.CONNECTED)
.then((data) => {
console.info('updateContinuationState finished, ' + JSON.stringify(data));
})
.catch((err) => {
.catch((err: BusinessError) => {
console.error('updateContinuationState failed, cause: ' + JSON.stringify(err));
});
} catch (err) {
......@@ -1122,7 +1150,8 @@ unregister(token: number, callback: AsyncCallback\<void>): void;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
continuationManager.unregister(token, (err, data) => {
if (err.code != 0) {
console.error('unregister failed, cause: ' + JSON.stringify(err));
......@@ -1167,12 +1196,13 @@ unregister(token: number): Promise\<void>;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = 1;
continuationManager.unregister(token)
.then((data) => {
console.info('unregister finished, ' + JSON.stringify(data));
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('unregister failed, cause: ' + JSON.stringify(err));
});
```
......@@ -1206,7 +1236,9 @@ unregisterContinuation(token: number, callback: AsyncCallback\<void>): void;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = 1;
try {
continuationManager.unregisterContinuation(token, (err, data) => {
if (err.code != 0) {
......@@ -1254,13 +1286,13 @@ unregisterContinuation(token: number): Promise\<void>;
**示例:**
```ts
let token = 1;
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = -1;
try {
continuationManager.unregisterContinuation(token)
.then((data) => {
continuationManager.unregisterContinuation(token).then((data) => {
console.info('unregisterContinuation finished, ' + JSON.stringify(data));
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err));
});
} catch (err) {
......
......@@ -35,32 +35,33 @@ registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback,
**示例:**
```ts
function NotifyMissionsChanged(deviceId) {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
function NotifyMissionsChanged(deviceId: string): void {
console.log('NotifyMissionsChanged deviceId ' + JSON.stringify(deviceId));
}
function NotifySnapshot(deviceId, missionId) {
function NotifySnapshot(deviceId: string, missionId: number): void {
console.log('NotifySnapshot deviceId ' + JSON.stringify(deviceId));
console.log('NotifySnapshot missionId ' + JSON.stringify(missionId));
}
function NotifyNetDisconnect(deviceId, state) {
function NotifyNetDisconnect(deviceId: string, state: number): void {
console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId));
console.log('NotifyNetDisconnect state ' + JSON.stringify(state));
}
var parameter = {
deviceId: ""
};
var options = {
try {
distributedMissionManager.registerMissionListener(
{ deviceId: "" },
{
notifyMissionsChanged: NotifyMissionsChanged,
notifySnapshot: NotifySnapshot,
notifyNetDisconnect: NotifyNetDisconnect
}
try {
distributedMissionManager.registerMissionListener(parameter, options, (error) => {
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('registerMissionListener failed, cause: ' + JSON.stringify(error))
}
console.info('registerMissionListener finished')
})
});
} catch (error) {
console.error('registerMissionListener failed, cause: ' + JSON.stringify(error))
}
......@@ -91,30 +92,29 @@ registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback):
**示例:**
```ts
function NotifyMissionsChanged(deviceId) {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
function NotifyMissionsChanged(deviceId: string): void {
console.log('NotifyMissionsChanged deviceId ' + JSON.stringify(deviceId));
}
function NotifySnapshot(deviceId, missionId) {
function NotifySnapshot(deviceId: string, missionId: number): void {
console.log('NotifySnapshot deviceId ' + JSON.stringify(deviceId));
console.log('NotifySnapshot missionId ' + JSON.stringify(missionId));
}
function NotifyNetDisconnect(deviceId, state) {
function NotifyNetDisconnect(deviceId: string, state: number): void {
console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId));
console.log('NotifyNetDisconnect state ' + JSON.stringify(state));
}
var parameter = {
deviceId: ""
};
var options = {
try {
distributedMissionManager.registerMissionListener(
{ deviceId: "" },
{
notifyMissionsChanged: NotifyMissionsChanged,
notifySnapshot: NotifySnapshot,
notifyNetDisconnect: NotifyNetDisconnect
}
try {
distributedMissionManager.registerMissionListener(parameter, options)
.then(data => {
}).then((data: void) => {
console.info('registerMissionListener finished, ' + JSON.stringify(data));
}).catch(error => {
}).catch((error: BusinessError) => {
console.error('registerMissionListener failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
......@@ -142,11 +142,12 @@ unRegisterMissionListener(parameter: MissionDeviceInfo, callback: AsyncCallback&
**示例:**
```ts
var parameter = {
deviceId: ""
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.unRegisterMissionListener(parameter, (error) => {
distributedMissionManager.unRegisterMissionListener(
{ deviceId: "" },
(error: BusinessError) => {
if (error.code != 0) {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error))
}
......@@ -182,14 +183,12 @@ unRegisterMissionListener(parameter: MissionDeviceInfo): Promise&lt;void&gt;
**示例:**
```ts
var parameter = {
deviceId: ""
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.unRegisterMissionListener(parameter)
.then(data => {
console.info('unRegisterMissionListener finished, ' + JSON.stringify(data));
}).catch(error => {
distributedMissionManager.unRegisterMissionListener({deviceId: ""}).then(() => {
console.info('unRegisterMissionListener finished successfully');
}).catch((error: BusinessError) => {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
......@@ -217,18 +216,21 @@ startSyncRemoteMissions(parameter: MissionParameter, callback: AsyncCallback&lt;
**示例:**
```ts
var parameter = {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.startSyncRemoteMissions(
{
deviceId: "",
fixConflict: false,
tag: 0
};
try {
distributedMissionManager.startSyncRemoteMissions(parameter, (error) => {
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
console.info('startSyncRemoteMissions finished')
})
console.info('startSyncRemoteMissions finished')}
)
} catch (error) {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
......@@ -259,16 +261,18 @@ startSyncRemoteMissions(parameter: MissionParameter): Promise&lt;void&gt;
**示例:**
```ts
var parameter = {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.startSyncRemoteMissions(
{
deviceId: "",
fixConflict: false,
tag: 0
};
try {
distributedMissionManager.startSyncRemoteMissions(parameter)
.then(data => {
console.info('startSyncRemoteMissions finished, ' + JSON.stringify(data));
}).catch(error => {
}
).then(() => {
console.info('startSyncRemoteMissions finished successfully');
}).catch((error: BusinessError) => {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
......@@ -296,16 +300,19 @@ stopSyncRemoteMissions(parameter: MissionDeviceInfo, callback: AsyncCallback&lt;
**示例:**
```ts
var parameter = {
deviceId: ""
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.stopSyncRemoteMissions(parameter, (error) => {
distributedMissionManager.stopSyncRemoteMissions(
{
deviceId: ""
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
console.info('stopSyncRemoteMissions finished')
})
console.info('stopSyncRemoteMissions finished')}
)
} catch (error) {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
......@@ -336,14 +343,15 @@ stopSyncRemoteMissions(parameter: MissionDeviceInfo): Promise&lt;void&gt;
**示例:**
```ts
var parameter = {
deviceId: ""
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.stopSyncRemoteMissions(parameter)
.then(data => {
console.info('stopSyncRemoteMissions finished, ' + JSON.stringify(data));
}).catch(error => {
distributedMissionManager.stopSyncRemoteMissions(
{
deviceId: ""
}).then((data: void) => {
console.info('stopSyncRemoteMissions finished successfully');
}).catch((error: BusinessError) => {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
......@@ -385,20 +393,21 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callba
**示例:**
```ts
var parameter = {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
function onContinueDone(resultCode: number): void {
console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode));
};
try {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
missionId: 1,
wantParam: {"key": "value"}
};
function onContinueDone(resultCode) {
console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode));
};
var options = {
onContinueDone: onContinueDone
};
try {
distributedMissionManager.continueMission(parameter, options, (error) => {
},
{ onContinueDone: onContinueDone },
(error: BusinessError) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
......@@ -448,23 +457,22 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promi
**示例:**
```ts
var parameter = {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
function onContinueDone(resultCode: number): void {
console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode));
};
try {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
missionId: 1,
wantParam: {"key": "value"}
};
function onContinueDone(resultCode) {
console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode));
};
var options = {
onContinueDone: onContinueDone
};
try {
distributedMissionManager.continueMission(parameter, options)
.then(data => {
console.info('continueMission finished, ' + JSON.stringify(data));
}).catch(error => {
},
{ onContinueDone: onContinueDone }).then(() => {
console.info('continueMission finished successfully');
}).catch((error: BusinessError) => {
console.error('continueMission failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
......@@ -505,14 +513,17 @@ continueMission(parameter: ContinueMissionInfo, callback: AsyncCallback&lt;void&
**示例:**
```ts
var parameter = {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
};
try {
distributedMissionManager.continueMission(parameter, (error) => {
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
......@@ -561,17 +572,19 @@ continueMission(parameter: ContinueMissionInfo): Promise&lt;void&gt;
**示例:**
```ts
var parameter = {
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
};
try {
distributedMissionManager.continueMission(parameter)
.then(data => {
console.info('continueMission finished, ' + JSON.stringify(data));
}).catch(error => {
}
).then(() => {
console.info('continueMission finished successfully');
}).catch((error: BusinessError) => {
console.error('continueMission failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
......@@ -599,12 +612,13 @@ on(type: 'continueStateChange', callback: Callback&lt;{ state: ContinueState, i
**示例:**
```js
import distributedMissionManager from '@ohos.distributedMissionManager'
try {
distributedMissionManager.on('continueStateChange', (data) => {
console.info("continueStateChange on:" + JSON.stringify(data));
});
} catch (err) {
console.error("continueStateChange errCode:" + err.code + ",errMessage:" + err.message);
} catch (error) {
console.error("continueStateChange err: " + JSON.stringify(error));
}
```
......@@ -628,12 +642,13 @@ off(type: 'continueStateChange', callback?: Callback&lt;{ state: ContinueState,
**示例:**
```js
import distributedMissionManager from '@ohos.distributedMissionManager'
try {
distributedMissionManager.off('continueStateChange', (data) => {
console.info("continueStateChange on:" + JSON.stringify(data));
console.info("continueStateChange off:" + JSON.stringify(data));
});
} catch (err) {
console.error("continueStateChange errCode:" + err.code + ",errMessage:" + err.message);
console.error("continueStateChange err: " + JSON.stringify(error));
}
```
......
......@@ -25,13 +25,13 @@ import distributedMissionManager from '@ohos.distributedMissionManager';
**示例:**
```js
import distributedMissionManager from '@ohos.distributedMissionManager';
import distributedMissionManager from '@ohos.distributedMissionManager';
try {
try {
distributedMissionManager.on('continueStateChange', (data) => {
console.info("continueStateChange on:" + JSON.stringify(data));
});
} catch (err) {
console.error("continueStateChange errCode:" + err.code + ",errMessage:" + err.message);
}
```
\ No newline at end of file
} catch (err) {
console.error("continueStateChange err: " + JSON.stringify(err));
}
```
\ No newline at end of file
......@@ -26,23 +26,22 @@ Mission迁移完成后调用,返回迁移结果。
```ts
import distributedMissionManager from '@ohos.distributedMissionManager';
import { BusinessError } from '@ohos.base';
let continueDeviceInfo = {
distributedMissionManager.continueMission(
{
srcDeviceId: '123',
dstDeviceId: '456',
missionId: 123,
wantParam: {
'key':'value'
}
};
let continueCallback = {
},
{
onContinueDone(result) {
console.log('onContinueDone, result: ${JSON.stringify(result)}');
}
};
distributedMissionManager.continueMission(continueDeviceInfo, continueCallback, (error) => {
}, (error: BusinessError) => {
if (error && error.code) {
console.error('continueMission failed, error.code: ${error.code}, error.message: ${error.message}');
}
......
......@@ -24,22 +24,20 @@
```ts
import distributedMissionManager from '@ohos.distributedMissionManager';
let continueDeviceInfo = {
distributedMissionManager.continueMission(
{
srcDeviceId: '123',
dstDeviceId: '456',
missionId: 123,
wantParam: {
'key':'value'
}
};
let continueCallback = {
onContinueDone(result) {
},
{
onContinueDone(result): void {
console.log('onContinueDone, result: ${JSON.stringify(result)}');
}
};
distributedMissionManager.continueMission(continueDeviceInfo, continueCallback, (error) => {
}, (error) => {
if (error && error.code) {
console.error('continueMission failed, error.code: ${error.code}, error.message: ${error.message}');
}
......
......@@ -28,15 +28,16 @@ import distributedMissionManager from '@ohos.distributedMissionManager';
```ts
import distributedMissionManager from '@ohos.distributedMissionManager';
import { BusinessError } from '@ohos.base';
var parameter = {
try {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
};
try {
distributedMissionManager.continueMission(parameter, (error) => {
}, (error: BusinessError) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册