HarmonyOS 跨设备发送文件,无法发送和接收

使用SharedData,无法搜索到用户,只能分享text文本

HarmonyOS
2024-12-25 07:28:36
978浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

可以参考下如下demo:

import { systemShare } from '@kit.ShareKit';
import { common } from '@kit.AbilityKit';
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
import fs, { ReadOptions, WriteOptions } from '@ohos.file.fs';
import { BusinessError, print } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';
  private pathDir: string = '/data/storage/el2/base/haps/entry/files'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            let data: systemShare.SharedData = new systemShare.SharedData({
              utd: utd.UniformDataType.FILE,
              content: 'testShare',
              uri: 'file://com.example.pickerdemo/data/storage/el2/base/haps/entry/files/testShare.pdf'
              // uri:'file://com.example.pickerdemo/data/storage/el2/base/haps/entry/files/printImage.png'
            });
            let controller: systemShare.ShareController = new systemShare.ShareController(data);
            let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
            controller.on('dismiss', () => {
              console.log('Share panel closed');
            });
            controller.show(context, {
              previewMode: systemShare.SharePreviewMode.DETAIL,
              selectionMode: systemShare.SelectionMode.SINGLE
            });
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
分享
微博
QQ
微信
回复
2024-12-25 10:42:30


相关问题
udp服务信号是如何发送接收
2737浏览 • 1回复 待解决
HarmonyOS 发送event接收不到
688浏览 • 1回复 待解决
webview如何进行消息的发送以及接收
1327浏览 • 1回复 待解决
ws库发送过快是否会阻塞接收
2834浏览 • 1回复 待解决
ets TCPSocket连接无法发送消息?
4726浏览 • 1回复 待解决
HarmonyOS 怎么主动发送通知
716浏览 • 1回复 待解决
HarmonyOS 关于语音发送功能
842浏览 • 1回复 待解决
HarmonyOS 发送请求cookie信息
949浏览 • 1回复 待解决
HarmonyOS 如何发送icmp请求?
800浏览 • 1回复 待解决
HarmonyOS 通过数据线往真机发送文件
940浏览 • 1回复 待解决
HarmonyOS PB转ArrayBuffer发送失败
545浏览 • 1回复 待解决
HarmonyOS 如何发送通知或广播
893浏览 • 1回复 待解决
HarmonyOS TLSSocket发送消息报错
618浏览 • 1回复 待解决