From 84b03aed323d797a7b633ce5c9bf402ab10f4481 Mon Sep 17 00:00:00 2001 From: du-zhihai Date: Thu, 6 Apr 2023 22:26:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=8F=E5=90=8C=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E4=B8=8B=E8=B7=A8=E8=AE=BE=E5=A4=87=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8F=98=E5=8C=96=E6=84=9F=E7=9F=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=96=87=E6=A1=A3=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: du-zhihai Change-Id: I89e2b6a7ec73c14a846f04f25a4c94642e202837 --- .../hop-multi-device-collaboration.md | 10 +++- .../apis/js-apis-app-ability-uiAbility.md | 53 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/zh-cn/application-dev/application-models/hop-multi-device-collaboration.md b/zh-cn/application-dev/application-models/hop-multi-device-collaboration.md index c7d4a8c386..9c353df983 100644 --- a/zh-cn/application-dev/application-models/hop-multi-device-collaboration.md +++ b/zh-cn/application-dev/application-models/hop-multi-device-collaboration.md @@ -397,7 +397,7 @@ import Ability from '@ohos.app.ability.UIAbility'; ``` 2. 获取Caller通信接口。 - Ability的context属性实现了startAbilityByCall方法,用于获取指定通用组件的Caller通信接口。如下示例通过this.context获取Ability实例的context属性,使用startAbilityByCall拉起Callee被调用端并获取Caller通信接口,注册Caller的onRelease监听。应用开发者根据实际业务需要做相应处理。 + Ability的context属性实现了startAbilityByCall方法,用于获取指定通用组件的Caller通信接口。如下示例通过this.context获取Ability实例的context属性,使用startAbilityByCall拉起Callee被调用端并获取Caller通信接口,注册Caller的onRelease和onRemoteStateChange监听。应用开发者根据实际业务需要做相应处理。 ```ts @@ -418,6 +418,14 @@ console.info(`remote caller onRelease is called ${msg}`); }) console.info('remote caller register OnRelease succeed'); + // 注册caller的协同场景下跨设备组件状态变化监听通知 + try { + caller.onRemoteStateChange((str) => { + console.log('Remote state changed ' + str); + }); + } catch (error) { + console.log('Caller.onRemoteStateChange catch error, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}'); + } } }).catch((error) => { console.error(`get remote caller failed with ${error}`); diff --git a/zh-cn/application-dev/reference/apis/js-apis-app-ability-uiAbility.md b/zh-cn/application-dev/reference/apis/js-apis-app-ability-uiAbility.md index dcdd97f4ab..d2b42f3edc 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-app-ability-uiAbility.md +++ b/zh-cn/application-dev/reference/apis/js-apis-app-ability-uiAbility.md @@ -547,6 +547,49 @@ release(): void; } ``` + ## Caller.onRemoteStateChange + + onRemoteStateChange(callback: OnRemoteStateChangeCallback): void; + +注册协同场景下跨设备组件状态变化监听通知。 + +**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| callback | [OnRemoteStateChangeCallback](#onremotestatechangecallback) | 是 | 返回onRemoteStateChange回调结果。 | + +**示例:** + + ```ts + import UIAbility from '@ohos.app.ability.UIAbility'; + + let caller; + let dstDeviceId: string; + export default class MainAbility extends UIAbility { + onWindowStageCreate(windowStage: Window.WindowStage) { + this.context.startAbilityByCall({ + bundleName: 'com.example.myservice', + abilityName: 'MainUIAbility', + deviceId: dstDeviceId + }).then((obj) => { + caller = obj; + try { + caller.onRemoteStateChange((str) => { + console.log('Remote state changed ' + str); + }); + } catch (error) { + console.log('Caller.onRemoteStateChange catch error, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}'); + } + }).catch((err) => { + console.log('Caller GetCaller error, error.code: ${JSON.stringify(err.code)}, error.message: ${JSON.stringify(err.message)}'); + }); + } + } + ``` + ## Caller.on on(type: 'release', callback: OnReleaseCallback): void; @@ -814,6 +857,16 @@ off(method: string): void; | -------- | -------- | -------- | -------- | -------- | | (msg: string) | 是 | 否 | function | 调用者注册的侦听器函数接口的原型。 | +## OnRemoteStateChangeCallback + +(msg: string): void; + +**系统能力**:SystemCapability.Ability.AbilityRuntime.AbilityCore + +| 名称 | 可读 | 可写 | 类型 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| (msg: string) | 是 | 否 | function | 调用者注册的协同场景下组件状态变化监听函数接口的原型。 | + ## CalleeCallback (indata: rpc.MessageSequence): rpc.Parcelable; -- GitLab