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)
})
}
}
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、然后长按分享到app。
打开了app界面,但是log中getSharedData一条都没有。
热启动会走onNewWant生命周期,可以在onNewWant内获取到want并处理数据,参考文档:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-app-ability-uiability-V5\#uiabilityonnewwant