From 44372968e268a4d4aeb4816b3fd7e6e05e3518f0 Mon Sep 17 00:00:00 2001 From: "1362134550@qq.com" <1362134550@qq.com> Date: Tue, 22 Jul 2025 17:04:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A2=B0=E4=B8=80=E7=A2=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E4=BA=AB=20=20=E5=9B=BE=E7=89=87=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + .../main/ets/controller/KnockController.ets | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3202e70..621a9fd 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ 2. 在首页勾选文件后,通过碰一碰即可分享已选文件。 3. 若接收端为PC设备,需确保手机与PC登录同一华为账号,方可实现碰一碰分享。 4. 接收端文件默认存储于图库或文件管理器中,其中PC端应用可通过调用harmonyShare.on('dataReceive')方法注册文件接收监听,碰一碰传输的文件将存储至该应用的沙箱路径下。 +5. PC端应用接收时最大支持接收5个支持。 ### 工程结构 diff --git a/entry/src/main/ets/controller/KnockController.ets b/entry/src/main/ets/controller/KnockController.ets index 7b65f44..95dc7f9 100644 --- a/entry/src/main/ets/controller/KnockController.ets +++ b/entry/src/main/ets/controller/KnockController.ets @@ -140,7 +140,16 @@ export class KnockController { public dataReceiveListeningPC() { window.getLastWindow(this.context).then(((data) => { let mainWindowID: number = data.getWindowProperties().id; - harmonyShare.on('dataReceive', { windowId: mainWindowID, capabilities: [] }, + harmonyShare.on('dataReceive', { windowId: mainWindowID, capabilities: [ + { + 'utd': uniformTypeDescriptor.UniformDataType.MEDIA, + 'maxSupportedCount': 5 + }, + { + 'utd': uniformTypeDescriptor.UniformDataType.FILE, + 'maxSupportedCount': 5 + } + ] }, (receiveTarget: harmonyShare.ReceivableTarget) => { if (!this.context) { return; @@ -197,7 +206,16 @@ export class KnockController { public dataReceiveDisableListeningPC() { window.getLastWindow(this.context).then(((data) => { let mainWindowID: number = data.getWindowProperties().id; - harmonyShare.off('dataReceive', { windowId: mainWindowID, capabilities: [] }); + harmonyShare.off('dataReceive', { windowId: mainWindowID, capabilities: [ + { + 'utd': uniformTypeDescriptor.UniformDataType.MEDIA, + 'maxSupportedCount': 5 + }, + { + 'utd': uniformTypeDescriptor.UniformDataType.FILE, + 'maxSupportedCount': 5 + } + ] }); })).catch((error: BusinessError) => { hilog.error(0x0000, 'KnockFileShare', `failed to obtain the window. cause ${error.code} ${error.message}`); }) -- Gitee