android 定向分享app

业务需求:同时分享多张图片(参照采源宝APP),实现至少对QQ好友,微博,微信,微信朋友圈的分享

qq,微博,微信的接入sdk文档中并没有提供多图分享的接口,shareSDK中针对相关app的权限做了优化,但是并没有提供多图分享功能,所以考虑自己构造一个intent并设置

new ArrayList<Uri> listLoadedShareUris = new ArrayList<>();
String exmpaleImagePath = "";//此处应用一个本地图片地址替代
File tempFile = new File(exmpaleImagePath);
listLoadedShareUris.add(Uri.fromFile(tempFile));//可添加多个Uri
Intent shareIntent = new Intent();    
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);    
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, listShareUris);    
shareIntent.setType("image/*");

然后根据提示的弹框选择需要的程序即可
如果希望过滤掉某些选项,需要用intent.createChooser()做一些过滤,具体就不在这儿展开了
关于定向APP的特定分享方式,通过

intent.setPackage();//设置目标APP
intent.setClassName();//设置目标APP的特定class来指定分享方式(比如微信的朋友圈,好友,收藏之间的区分)

这两个方法对intent进行设置后startActivity(intent)即可,下面是常用的几个分享

shareIntent.setPackage("com.sina.weibo");    
shareIntent.setClassName("com.sina.weibo", "com.sina.weibo.composerinde.ComposerDispatchActivity");    
type = "微博";    

shareIntent.setPackage("com.tencent.mobileqq");    
shareIntent.setClassName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");    
type = "QQ";    

shareIntent.setPackage("com.tencent.mm");    
shareIntent.setClassName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI");   
 type = "朋友圈";    

shareIntent.setPackage("com.tencent.mm");    
shareIntent.setClassName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");    
type = "微信好友";

TODO:X 分享到微信朋友圈时,如何携带文字内容(考虑: 1.inetnt设置相关参数; 2.setClassName中class需要重新选择)

注:
关于intentchooser和setPackage() setClassName()中参数的获取参见
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/1005/1564.html



作者:Qsy_Zer0
链接:http://www.jianshu.com/p/1867b9c71503
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自blog.csdn.net/u014261855/article/details/76386015