2022-01-27 uniapp app内唤起系统分享

1643249906(1).png

只需要勾选第一个,其他的没用到不要勾选

/**
* 调用系统分享
*/
export function shareSystem(share_url) {
  console.log('调用系统分享');
  var msg = { content: "我喜欢这个菜谱:", href: share_url };
  plus.share.sendWithSystem ? plus.share.sendWithSystem(msg, function () {
    console.log('Success');
  }, function (e) {
    console.log('Failed: ' + JSON.stringify(e));
  }) : shareSystemNativeJS();
}

function shareSystemNativeJS() {
  if (plus.os.name !== 'Android') {
    plus.nativeUI.alert('此平台暂不支持系统分享功能!');
    return;
  }
  var intent = new Intent(Intent.ACTION_SEND);
  intent.setType('text/plain');
  intent.putExtra(Intent.EXTRA_SUBJECT, 'HelloH5');
  intent.putExtra(Intent.EXTRA_TEXT, sharecontent.value);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  main.startActivity(Intent.createChooser(intent, '系统分享HelloH5'));
}

自定义基座是依赖浏览器环境,仍可以唤起分享,但打包后真机唤不起系统分享,所以需要判断安卓环境

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容