文档开发者中心
我的
|

ArkUI (方舟UI框架)

UI

Ability框架

华为分享

arkts api9使用分享应用数据打开底部弹框分享

下载的文件保存到沙盒的,需要打开,目前是使用API9下的分享功能,但是一直报异常,请各位大神看看,是什么问题导致的

收起
自动换行
深色代码主题
复制
const filePath = `${context.filesDir + '/'}${saveName}`;// 这个是下载保存在沙盒的路径
收起
自动换行
深色代码主题
复制
let fileFd = fileIO.openSync(filePath, 0o102, 0o666);
let want = {
  // This action is used to implicitly match the application selctor.
  action: wantConstant.Action.ACTION_SELECT,
  // This is the custom parameter in the first layer of want
  // which is intended to add info to application selector.
  parameters: {
    // The MIME type of pdf
    "ability.picker.type": "application/pdf",
    "ability.picker.fileNames": [filePath],
    "ability.picker.fileSizes": [100 * 1024],
    // This a nested want which will be directly send to the user selected application.
    "ability.want.params.INTENT": {
      "action": "ohos.want.action.sendData",
      "type": "application/pdf",
      "parameters": {
        "keyFd": { "type": "FD", "value": fileFd }
      }
    }
  }
}
context.startAbility(want)
  .then(() => {
    console.info('Invoke getCurrentBundleStats succeeded.');
  })
  .catch((err) => {
    console.error(`Invoke startAbility failed, code is ${err.code}, message is ${err.message}`);  // 这里报异常
  });

配置也配置了。

cke_5490.png

cke_4118.png

截图是错误信息。

点赞
1
收藏
回复
2
分享
举报
浏览538 发布于2024-03-05 07:13福建
全部评论
最多点赞
最新发布
最早发布

开发者您好,应用文件分享就支持跨应用分享文件
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V2/share-app-file-0000001456039582-V2

三方应用,startAbility 的方式,拉起微博,可以分享多个文件给微博应用的
let want: Want = {
action: “ohos.want.action.sendData”,
parameters: {
“ability.params.stream”: uris
},
flags: mode,
bundleName: “com.demo.b”,
abilityName: “MainAbility”,
type: “text/plain”,
// deviceId: networkId,
uri: uri,
}

2楼回复于2024-03-21 10:35 来自广东
楼主您好,该问题已反馈至相关人员,请耐心等待。
1楼回复于2024-03-17 07:58 来自广东
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要提问题

了解社区公约,与您携手共创和谐专业的开发者社区。