王者地带
王者地带
  • 发布:2019-08-08 17:02
  • 更新:2023-06-24 16:26
  • 阅读:3212

Android 使用 Native.js 调用系统分享 文件给第三应用 QQ、微信 达到发送文件给朋友

分类:Native.js

当应用内,需要把图片或视频或压缩文件等等文件,发给第三方应用时,可以使用Native.js调用系统自带的分享功能来实现.

var main = plus.android.runtimeMainActivity();  
var Intent = plus.android.importClass("android.content.Intent");  
var Uri = plus.android.importClass("android.net.Uri");  
var File = plus.android.importClass("java.io.File");  
var shareIntent = new Intent(Intent.ACTION_SEND);  

var filePath=plus.io.convertLocalFileSystemURL("img/3.jpg"); //把应用内的文件路径转化为手机绝对路径  

shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath)));  
shareIntent.setType("*/*");//此处可发送多种文件  
//shareIntent.setType("application/pdf");//只发送pdf文件  

main.startActivity(Intent.createChooser(shareIntent,"分享文件"));  

http://www.html5-app.com/uploads/file/20181218/20181218193232344354.jpg

原文链接

0 关注 分享

要回复文章请先登录注册

3***@qq.com

3***@qq.com

回复 6***@qq.com :
有解决的办法吗
2023-06-24 16:26
4***@qq.com

4***@qq.com

最新版本的好像用不了,startactivity没反应,但是我加了void plus.runtime.openFile( filePath);就可以弹出来,请问是怎么回事(而且openfile的窗口会被顶掉,不影响最终结果)
2021-08-25 23:48
6***@qq.com

6***@qq.com

Uncaught android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/s/a.jpg exposed beyond app through ClipData.Item.getUri();at io.dcloud.PandoraEntryActivity.startActivity at index.html:1
2021-01-13 09:53
gangder

gangder

新版框架,这个功能挂了,你的还好嘛?
提示 undefined
2019-10-03 00:17
gangder

gangder

新版框架,这个功能持了,你的还好嘛?
2019-10-02 23:33
2***@qq.com

2***@qq.com

能固定选择某个应用么?
2019-08-09 17:18