提交 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,
}
]
......@@ -84,20 +84,24 @@
- 迁移决策:开发者可以通过onContinue接口的返回值决定是否支持此次迁移,返回值信息见[接口说明](#接口说明)
示例如下:
```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}`) //准备迁移数据
let continueInput = '迁移的数据';
// 将要迁移的数据保存在wantParam的自定义字段(如:data)中;
wantParam["data"] = continueInput
console.info(`onContinue input = ${wantParam["input"]}`);
return AbilityConstant.OnContinueResult.AGREE
}
```
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
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["data"]}`);
return AbilityConstant.OnContinueResult.AGREE;
}
}
```
5.在Stage模型中,应用在不同启动模式下将调用不同的接口,以恢复数据、加载界面。
......@@ -113,42 +117,51 @@ onContinue(wantParam : {[key: string]: Object}) {
- 完成数据恢复后,开发者需要调用restoreWindowStage来触发页面恢复:包括页面栈信息。
```ts
import UIAbility from '@ohos.app.ability.UIAbility';
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onCreate(want, launchParam) {
console.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// 将上述的保存的数据取出恢复
let continueInput = want.parameters.data
console.info(`continue input ${continueInput}`)
// 将数据显示当前页面
this.storage = new LocalStorage();
this.context.restoreWindowStage(this.storage);
}
}
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 = new LocalStorage();
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
console.info(`EntryAbility onCreate ${AbilityConstant.LaunchReason.CONTINUATION}`)
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
// 将上述的保存的数据取出恢复
let continueInput = '';
if (want.parameters != undefined) {
continueInput = JSON.stringify(want.parameters.data);
console.info(`continue input ${continueInput}`)
}
// 将数据显示当前页面
this.context.restoreWindowStage(this.storage);
}
}
}
```
- 如果是单实例应用,需要额外实现onNewWant接口,实现方式与onCreate的实现相同。
- 在onNewWant中判断迁移场景,恢复数据,并触发页面恢复
```ts
export default class EntryAbility extends UIAbility {
storage : LocalStorage;
onNewWant(want, launchParam) {
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();
this.context.restoreWindowStage(this.storage);
}
}
```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 = 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 = '';
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(){
...
// 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));
});
})
}
}
.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) {
...
// 调用原因为迁移时,设置状态为可迁移,应对冷启动情况
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
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)}`);
});
}
}
onNewWant(want, launchparam) {
...
// 调用原因为迁移时,设置状态为可迁移,应对热启动情况
if (launchParam.launchReason == AbilityConstant.LaunchReason.CONTINUATION) {
this.context.setMissionContinueState(AbilityConstant.ContinueState.ACTIVE, (result) => {
console.info('setMissionContinueState ACTIVE result: ', JSON.stringify(result));
};
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) {
// 若不需要自动迁移页面栈信息,则需要在此处设置应用迁移后进入的页面
windowStage.setUIContent(this.contex, "pages/index", null);
}
// ...
onWindowStageRestore(windowStage: window.WindowStage) {
// 若不需要自动迁移页面栈信息,则需要在此处设置应用迁移后进入的页面
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,12 +321,16 @@ 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;
}
// ...
}
```
......
......@@ -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,17 +86,19 @@ register(options: ContinuationExtraParams, callback: AsyncCallback\<number>): vo
**示例:**
```ts
let token = -1;
let continuationExtraParams = {
deviceType: ["00E"]
};
continuationManager.register(continuationExtraParams, (err, data) => {
if (err.code != 0) {
console.error('register failed, cause: ' + JSON.stringify(err));
return;
}
console.info('register finished, ' + JSON.stringify(data));
token = data;
import continuationManager from '@ohos.continuation.continuationManager'
let token: number = -1;
continuationManager.register(
{
deviceType: ["00E"]
},
(err, data) => {
if (err.code != 0) {
console.error('register failed, cause: ' + JSON.stringify(err));
return;
}
console.info('register finished, ' + JSON.stringify(data));
token = data;
});
```
......@@ -135,18 +138,16 @@ 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));
});
});
```
## continuationManager.registerContinuation<sup>9+</sup>
......@@ -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,18 +223,20 @@ 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) => {
if (err.code != 0) {
console.error('registerContinuation failed, cause: ' + JSON.stringify(err));
return;
}
console.info('registerContinuation finished, ' + JSON.stringify(data));
token = data;
continuationManager.registerContinuation(
{
deviceType: ["00E"]
},
(err, data) => {
if (err.code != 0) {
console.error('registerContinuation failed, cause: ' + JSON.stringify(err));
return;
}
console.info('registerContinuation finished, ' + JSON.stringify(data));
token = data;
});
} catch (err) {
console.error('registerContinuation failed, cause: ' + JSON.stringify(err));
......@@ -273,19 +277,19 @@ 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) {
console.error('registerContinuation failed, cause: ' + JSON.stringify(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,16 +703,19 @@ startDeviceManager(token: number, options: ContinuationExtraParams, callback: As
**示例:**
```ts
let token = 1;
let continuationExtraParams = {
deviceType: ["00E"]
};
continuationManager.startDeviceManager(token, continuationExtraParams, (err, data) => {
if (err.code != 0) {
console.error('startDeviceManager failed, cause: ' + JSON.stringify(err));
return;
}
console.info('startDeviceManager finished, ' + JSON.stringify(data));
import continuationManager from '@ohos.continuation.continuationManager';
let token: number = 1;
continuationManager.startDeviceManager(
token,
{
deviceType: ["00E"]
},
(err, data) => {
if (err.code != 0) {
console.error('startDeviceManager failed, cause: ' + JSON.stringify(err));
return;
}
console.info('startDeviceManager finished, ' + JSON.stringify(data));
});
```
......@@ -742,17 +758,18 @@ startDeviceManager(token: number, options?: ContinuationExtraParams): Promise\<v
**示例:**
```ts
let token = 1;
let continuationExtraParams = {
deviceType: ["00E"]
};
continuationManager.startDeviceManager(token, continuationExtraParams)
.then((data) => {
import continuationManager from '@ohos.continuation.continuationManager';
import { BusinessError } from '@ohos.base';
let token: number = -1;
continuationManager.startDeviceManager(
token,
{
deviceType: ["00E"]
}).then((data) => {
console.info('startDeviceManager finished, ' + JSON.stringify(data));
})
.catch((err) => {
}).catch((err: BusinessError) => {
console.error('startDeviceManager failed, cause: ' + JSON.stringify(err));
});
});
```
## continuationManager.startContinuationDeviceManager<sup>9+</sup>
......@@ -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,17 +846,20 @@ 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) => {
if (err.code != 0) {
console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
return;
}
console.info('startContinuationDeviceManager finished, ' + JSON.stringify(data));
continuationManager.startContinuationDeviceManager(
token,
{
deviceType: ["00E"]
},
(err, data) => {
if (err.code != 0) {
console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
return;
}
console.info('startContinuationDeviceManager finished, ' + JSON.stringify(data));
});
} catch (err) {
console.error('startContinuationDeviceManager failed, cause: ' + JSON.stringify(err));
......@@ -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,15 +1006,17 @@ 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));
});
});
```
## continuationManager.updateContinuationState<sup>9+</sup>
......@@ -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,14 +1196,15 @@ 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));
});
});
```
## continuationManager.unregisterContinuation<sup>9+</sup>
......@@ -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,15 +1286,15 @@ 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) {
console.error('unregisterContinuation failed, cause: ' + JSON.stringify(err));
}
......
......@@ -35,34 +35,35 @@ registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback,
**示例:**
```ts
function NotifyMissionsChanged(deviceId) {
console.log('NotifyMissionsChanged deviceId ' + JSON.stringify(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) {
console.log('NotifySnapshot deviceId ' + JSON.stringify(deviceId));
console.log('NotifySnapshot missionId ' + JSON.stringify(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) {
console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId));
console.log('NotifyNetDisconnect state ' + JSON.stringify(state));
}
var parameter = {
deviceId: ""
};
var options = {
notifyMissionsChanged: NotifyMissionsChanged,
notifySnapshot: NotifySnapshot,
notifyNetDisconnect: NotifyNetDisconnect
function NotifyNetDisconnect(deviceId: string, state: number): void {
console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId));
console.log('NotifyNetDisconnect state ' + JSON.stringify(state));
}
try {
distributedMissionManager.registerMissionListener(parameter, options, (error) => {
if (error.code != 0) {
console.error('registerMissionListener failed, cause: ' + JSON.stringify(error))
}
console.info('registerMissionListener finished')
})
distributedMissionManager.registerMissionListener(
{ deviceId: "" },
{
notifyMissionsChanged: NotifyMissionsChanged,
notifySnapshot: NotifySnapshot,
notifyNetDisconnect: NotifyNetDisconnect
},
(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))
console.error('registerMissionListener failed, cause: ' + JSON.stringify(error))
}
```
## distributedMissionManager.registerMissionListener
......@@ -91,30 +92,29 @@ registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback):
**示例:**
```ts
function NotifyMissionsChanged(deviceId) {
console.log('NotifyMissionsChanged deviceId ' + JSON.stringify(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) {
console.log('NotifySnapshot deviceId ' + JSON.stringify(deviceId));
console.log('NotifySnapshot missionId ' + JSON.stringify(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) {
console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId));
console.log('NotifyNetDisconnect state ' + JSON.stringify(state));
}
var parameter = {
deviceId: ""
};
var options = {
notifyMissionsChanged: NotifyMissionsChanged,
notifySnapshot: NotifySnapshot,
notifyNetDisconnect: NotifyNetDisconnect
function NotifyNetDisconnect(deviceId: string, state: number): void {
console.log('NotifyNetDisconnect deviceId ' + JSON.stringify(deviceId));
console.log('NotifyNetDisconnect state ' + JSON.stringify(state));
}
try {
distributedMissionManager.registerMissionListener(parameter, options)
.then(data => {
distributedMissionManager.registerMissionListener(
{ deviceId: "" },
{
notifyMissionsChanged: NotifyMissionsChanged,
notifySnapshot: NotifySnapshot,
notifyNetDisconnect: NotifyNetDisconnect
}).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,16 +142,17 @@ unRegisterMissionListener(parameter: MissionDeviceInfo, callback: AsyncCallback&
**示例:**
```ts
var parameter = {
deviceId: ""
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.unRegisterMissionListener(parameter, (error) => {
if (error.code != 0) {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error))
}
console.info('unRegisterMissionListener finished')
})
distributedMissionManager.unRegisterMissionListener(
{ deviceId: "" },
(error: BusinessError) => {
if (error.code != 0) {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error))
}
console.info('unRegisterMissionListener finished')
})
} catch (error) {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error))
}
......@@ -182,16 +183,14 @@ 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 => {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error));
})
distributedMissionManager.unRegisterMissionListener({deviceId: ""}).then(() => {
console.info('unRegisterMissionListener finished successfully');
}).catch((error: BusinessError) => {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
console.error('unRegisterMissionListener failed, cause: ' + JSON.stringify(error))
}
......@@ -217,20 +216,23 @@ startSyncRemoteMissions(parameter: MissionParameter, callback: AsyncCallback&lt;
**示例:**
```ts
var parameter = {
deviceId: "",
fixConflict: false,
tag: 0
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.startSyncRemoteMissions(parameter, (error) => {
if (error.code != 0) {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
console.info('startSyncRemoteMissions finished')
})
distributedMissionManager.startSyncRemoteMissions(
{
deviceId: "",
fixConflict: false,
tag: 0
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
console.info('startSyncRemoteMissions finished')}
)
} catch (error) {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
```
......@@ -259,20 +261,22 @@ startSyncRemoteMissions(parameter: MissionParameter): Promise&lt;void&gt;
**示例:**
```ts
var parameter = {
deviceId: "",
fixConflict: false,
tag: 0
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.startSyncRemoteMissions(parameter)
.then(data => {
console.info('startSyncRemoteMissions finished, ' + JSON.stringify(data));
}).catch(error => {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error));
})
distributedMissionManager.startSyncRemoteMissions(
{
deviceId: "",
fixConflict: false,
tag: 0
}
).then(() => {
console.info('startSyncRemoteMissions finished successfully');
}).catch((error: BusinessError) => {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
console.error('startSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
```
......@@ -296,18 +300,21 @@ 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) => {
if (error.code != 0) {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
console.info('stopSyncRemoteMissions finished')
})
distributedMissionManager.stopSyncRemoteMissions(
{
deviceId: ""
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
console.info('stopSyncRemoteMissions finished')}
)
} catch (error) {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
```
......@@ -336,18 +343,19 @@ 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 => {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(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) {
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
console.error('stopSyncRemoteMissions failed, cause: ' + JSON.stringify(error))
}
```
......@@ -385,27 +393,28 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callba
**示例:**
```ts
var parameter = {
srcDeviceId: "",
dstDeviceId: "",
missionId: 1,
wantParam: {"key": "value"}
};
function onContinueDone(resultCode) {
console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode));
};
var options = {
onContinueDone: onContinueDone
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(parameter, options, (error) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
console.info('continueMission finished')
})
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
missionId: 1,
wantParam: {"key": "value"}
},
{ onContinueDone: onContinueDone },
(error: BusinessError) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
console.info('continueMission finished')
})
} catch (error) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
```
......@@ -448,27 +457,26 @@ continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promi
**示例:**
```ts
var parameter = {
srcDeviceId: "",
dstDeviceId: "",
missionId: 1,
wantParam: {"key": "value"}
};
function onContinueDone(resultCode) {
console.log('onContinueDone resultCode: ' + JSON.stringify(resultCode));
};
var options = {
onContinueDone: onContinueDone
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(parameter, options)
.then(data => {
console.info('continueMission finished, ' + JSON.stringify(data));
}).catch(error => {
console.error('continueMission failed, cause: ' + JSON.stringify(error));
})
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
missionId: 1,
wantParam: {"key": "value"}
},
{ onContinueDone: onContinueDone }).then(() => {
console.info('continueMission finished successfully');
}).catch((error: BusinessError) => {
console.error('continueMission failed, cause: ' + JSON.stringify(error));
})
} catch (error) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
```
......@@ -505,21 +513,24 @@ continueMission(parameter: ContinueMissionInfo, callback: AsyncCallback&lt;void&
**示例:**
```ts
var parameter = {
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.continueMission(parameter, (error) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
console.info('continueMission finished')
})
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
},
(error: BusinessError) => {
if (error.code != 0) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
console.info('continueMission finished')
})
} catch (error) {
console.error('continueMission failed, cause: ' + JSON.stringify(error))
console.error('continueMission failed, cause: ' + JSON.stringify(error))
}
```
......@@ -561,17 +572,19 @@ continueMission(parameter: ContinueMissionInfo): Promise&lt;void&gt;
**示例:**
```ts
var parameter = {
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
};
import distributedMissionManager from '@ohos.distributedMissionManager'
import { BusinessError } from '@ohos.base';
try {
distributedMissionManager.continueMission(parameter)
.then(data => {
console.info('continueMission finished, ' + JSON.stringify(data));
}).catch(error => {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
}
).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';
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
import distributedMissionManager from '@ohos.distributedMissionManager';
try {
distributedMissionManager.on('continueStateChange', (data) => {
console.info("continueStateChange on:" + JSON.stringify(data));
});
} catch (err) {
console.error("continueStateChange err: " + JSON.stringify(err));
}
```
\ No newline at end of file
......@@ -26,26 +26,25 @@ 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}');
}
console.log('continueMission finished');
});
});
```
......@@ -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 = {
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
};
try {
distributedMissionManager.continueMission(parameter, (error) => {
distributedMissionManager.continueMission(
{
srcDeviceId: "",
dstDeviceId: "",
bundleName: "ohos.test.continueapp",
wantParam: {"key": "value"}
}, (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.
先完成此消息的编辑!
想要评论请 注册