HarmonyOS systemShare.getSharedData无法接收到数据

EntryAbility

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    systemShare.getSharedData(want)
      .then((data: systemShare.SharedData) => {
        LogUtil.i('getSharedData:receive')
        try {
          data.getRecords().forEach((record: systemShare.SharedRecord) => {
            LogUtil.i(`getSharedData:${JSON.stringify(record)}`)
          })
        } catch (err) {
          LogUtil.err('getSharedData', err as BusinessError)
        }
      })
      .catch((err: BusinessError) => {
        LogUtil.err('getSharedData', err)
      })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

module.json5

{
  "module": {
    ...
    "abilities": [
      {
        ...
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home",
              "ohos.want.action.sendData"
            ],
            "uris": [
              {
                "scheme": "file",
                "utd": "general.audio",
                "maxFileSupported": 1
              }
            ]
          }
        ]
      }
    ],
  }
}
  • 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.

操作步骤:

1、使用手机自带的录音机,录一条音频;

2、然后长按分享到app。

打开了app界面,但是log中getSharedData一条都没有。

HarmonyOS
2025-01-10 09:02:19
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

热启动会走onNewWant生命周期,可以在onNewWant内获取到want并处理数据,参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-app-ability-uiability-V5#uiabilityonnewwant

分享
微博
QQ
微信
回复
2025-01-10 11:18:49
相关问题
HarmonyOS 无法接收推送数据
915浏览 • 1回复 待解决
HarmonyOS 推送无法收到
753浏览 • 1回复 待解决
HarmonyOS 无法接收事件
933浏览 • 1回复 待解决
HarmonyOS 无法收到推送通知
928浏览 • 1回复 待解决
HarmonyOS 推送突然无法接收
573浏览 • 1回复 待解决
HarmonyOS 手机锁屏时无法收到推送吗?
1088浏览 • 1回复 待解决
HarmonyOS 服务端推送消息,SDK无法收到
1210浏览 • 1回复 待解决