From 47d29987ff99ae4639797a894074dbd7212a5f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E6=89=AC?= Date: Wed, 13 Aug 2025 10:53:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(commentPage):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E8=BE=93=E5=85=A5=E6=97=A0=E6=B3=95=E6=8B=89?= =?UTF-8?q?=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/entryability/EntryAbility.ets | 8 ++++++++ entry/src/main/ets/pages/CommentPage.ets | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 124592d..fcbb37b 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -23,6 +23,8 @@ export default class EntryAbility extends UIAbility { onContinue(wantParam: Record) { Logger.info(wantParam.version.toString(), wantParam.targetDevice.toString()); + // Get and save the target device info + AppStorage.setOrCreate('targetDevice', wantParam.targetDevice.toString()); // Preparing to Migrate Data let activeLive: number = AppStorage.get('activeLive') as number; @@ -38,6 +40,9 @@ export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { Logger.info('Ability onCreate'); + if (want.parameters?.deviceId !== undefined) { + AppStorage.setOrCreate('targetDevice', want.parameters?.deviceId.toString()); + }; this.checkPermissions(); // If the invoking reason is migration, set the status to migratable to cope with cold start (ensuring migration continuity) @@ -62,6 +67,9 @@ export default class EntryAbility extends UIAbility { onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) { Logger.info('Ability onCreate'); + if (want.parameters?.deviceId !== undefined) { + AppStorage.setOrCreate('targetDevice', want.parameters?.deviceId.toString()); + }; // If the invoking reason is migration, set the status to migratable to cope with hot start (ensuring migration continuity) if (launchParam.launchReason === AbilityConstant.LaunchReason.CONTINUATION) { diff --git a/entry/src/main/ets/pages/CommentPage.ets b/entry/src/main/ets/pages/CommentPage.ets index c3747aa..165b4de 100644 --- a/entry/src/main/ets/pages/CommentPage.ets +++ b/entry/src/main/ets/pages/CommentPage.ets @@ -22,7 +22,7 @@ import { LiveData } from '../model/LiveData'; import Constants from '../common/Constants'; import Logger from '../utils/Logger'; -function getRemoteDeviceId(): string | undefined { +function getRemoteDeviceId(targetDevice: string): string | undefined { let dmClass = distributedDeviceManager.createDeviceManager('com.example.codelab'); if (typeof dmClass === 'object' && dmClass !== null) { let list = dmClass.getAvailableDeviceListSync(); @@ -34,7 +34,12 @@ function getRemoteDeviceId(): string | undefined { Logger.error('getRemoteDeviceId err: list is null'); return; } - Logger.info(list[0].networkId as string); + for (const device of list) { + if (targetDevice !== '' && device.networkId=== targetDevice) { + Logger.info(device.networkId as string); + return device.networkId; + } + } return list[0].networkId; } else { Logger.error('getRemoteDeviceId err: dmClass is null'); @@ -49,6 +54,7 @@ export struct CommentPage { @State isPhone: boolean = false; @State @Watch("onLiveListUpdated") liveList: Array = []; @Link @Watch("onActiveUpdated") activeItem: number; + @StorageProp('targetDevice') targetDevice: string = ''; scroller: Scroller = new Scroller(); listenerIsPhone = this.getUIContext().getMediaQuery().matchMediaSync('(orientation:landscape)'); private context = this.getUIContext().getHostContext() as common.UIAbilityContext; @@ -155,7 +161,7 @@ export struct CommentPage { .visibility(deviceInfo.deviceType !== 'phone' ? Visibility.Visible : Visibility.None) .onClick(() => { let want: Want = { - deviceId: getRemoteDeviceId(), + deviceId: getRemoteDeviceId(this.targetDevice), bundleName: 'com.example.codelab', abilityName: 'InputAbility', }; -- Gitee From dc117db3e61da5850f3cdc014578e4dd82c5f487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E6=89=AC?= Date: Wed, 13 Aug 2025 19:50:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(commentPage):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=89=8B=E6=9C=BA=E8=BE=93=E5=85=A5=E6=97=A0=E6=B3=95=E6=8B=89?= =?UTF-8?q?=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/CommentPage.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entry/src/main/ets/pages/CommentPage.ets b/entry/src/main/ets/pages/CommentPage.ets index 165b4de..fa4340f 100644 --- a/entry/src/main/ets/pages/CommentPage.ets +++ b/entry/src/main/ets/pages/CommentPage.ets @@ -35,7 +35,7 @@ function getRemoteDeviceId(targetDevice: string): string | undefined { return; } for (const device of list) { - if (targetDevice !== '' && device.networkId=== targetDevice) { + if (targetDevice !== '' && device.networkId === targetDevice) { Logger.info(device.networkId as string); return device.networkId; } -- Gitee