android 多图分享到微信,android下分享多图到微信或使用系统分享遇到的问题

一定要注意 uri 的格式

content://media/external/images/media/581138 这是正确的本地路径格式

file:///content%3A/media/external/images/media/581139 不正确的本地路径格式

如果地址错误 就不会调起微信

/**

*

* @param 保存后的本地图片路径

*/

public void launchSystemShare(ArrayList imagePaths, Promise p) {

ArrayList uriList = new ArrayList<>();

//array为要分享图片的本地地址

for (int i = 0; i

//将所有的本地地址转换为Uri并添加至集合

uriList.add(Uri.parse(imagePaths.getString(i)));

//下面这种方式 我得到了错误的本地路径 导致一直无法调起微信

Log.e("11111",Uri.fromFile(new File(imagePaths.getString(i))).toString());

}

Intent shareIntent = new Intent();

// 如果打开这行代码注释 分享时直接调起微信列表 否则调起系统分享页面

// shareIntent.setComponent(new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI"));

//打开分享界面的Action

shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);

//指定分享的类型

shareIntent.setType("image/*");

//分享传递的数据

shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);

//打开分享

getCurrentActivity().startActivity(shareIntent);

}

如果是 android7.0 以上 需要在 MainApplication 的 onCreate 方法中添加以下代码

if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.N) {

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();

StrictMode.setVmPolicy(builder.build());

builder.detectFileUriExposure();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值