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

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

HarmonyOS
1天前
浏览
收藏 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%')
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
udp服务信号是如何发送接收
1813浏览 • 1回复 待解决
HarmonyOS 发送event接收不到
54浏览 • 1回复 待解决
ws库发送过快是否会阻塞接收
2095浏览 • 1回复 待解决
ets TCPSocket连接无法发送消息?
3997浏览 • 1回复 待解决
HarmonyOS 怎么主动发送通知
89浏览 • 1回复 待解决
HarmonyOS 关于语音发送功能
20浏览 • 1回复 待解决
HarmonyOS 如何发送icmp请求?
216浏览 • 1回复 待解决
HarmonyOS 发送请求cookie信息
43浏览 • 1回复 待解决
HarmonyOS 如何发送通知或广播
78浏览 • 1回复 待解决
如何发送字节流数据 ?
684浏览 • 1回复 待解决
HarmonyOS postman 发送推送消息失败
528浏览 • 0回复 待解决