#鸿蒙学习大百科#被分享方的UIAbility被拉起后,如何获取分享方传入的参数?

被分享方的UIAbility被拉起后,如何获取分享方传入的参数?

HarmonyOS
2024-10-22 15:29:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
努力向前进

可以在其onCreate()或者onNewWant回调中获取传入的Want参数信息。

onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {

  // 从want信息中获取uri字段
  let uri = want.uri;
  if (uri == null || uri == undefined) {
    console.info('uri is invalid');
    return;
  }
  try {
    // 根据需要对被分享文件的URI进行相应操作。例如读写的方式打开URI获取file对象
    let file = fs.openSync(uri, fs.OpenMode.READ_WRITE);
    console.info('open file successfully!');
  } catch (err) {
    let error: BusinessError = err as BusinessError;
    console.error(`Invoke openSync failed, code is ${error.code}, message is ${error.message}`);
  }
} catch (error) {
  let err: BusinessError = error as BusinessError;
  console.error(`Invoke openSync failed, code is ${err.code}, message is ${err.message}`);
}
}
分享
微博
QQ
微信
回复
2024-10-22 22:20:14
相关问题