#鸿蒙学习大百科#如何分享文件给其他应用?

如何分享文件给其他应用?

HarmonyOS
2024-10-22 15:21:22
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
风间爱小新V
  // 获取文件沙箱路径
  let filePath = this.context.filesDir + '/test.txt';
  // 将沙箱路径转换为uri
  let uri = fileUri.getUriFromPath(filePath);
  let want: Want  = {
    // 配置被分享文件的读写权限,例如对被分享应用进行读写授权
    flags: wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION | wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
    // 配置分享应用的隐式拉起规则
    action: 'ohos.want.action.sendData',
    uri: uri,
    type: 'text/plain'
  }
  this.context.startAbility(want)
    .then(() => {
      console.info('Invoke getCurrentBundleStats succeeded.');
    })
    .catch((err: BusinessError) => {
      console.error(`Invoke startAbility failed, code is ${err.code}, message is ${err.message}`);
    });
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
分享
微博
QQ
微信
回复
2024-10-22 21:59:24
相关问题
#鸿蒙学习大百科#什么是用户文件
832浏览 • 0回复 待解决
#鸿蒙学习大百科#什么是应用沙箱?
1005浏览 • 1回复 待解决