直接上代码:List<String> files为文件路径列表public static void shareMoreWxFile(Context context, List<String> files) {try {ArrayList uriArrayList = new ArrayList<Uri>();for (String path : files) {File file = new File(path);if (file.exists()) {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {//android 7.0以下uriArrayList.add(Uri.fromFile(file));} else {//android 7.0及以上Uri uri = Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), null));uriArrayList.add(uri);}}}if (uriArrayList.size() > 0) {Intent share = new Intent();ComponentName comp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI");share.setComponent(comp);share.setAction(Intent.ACTION_SEND_MULTIPLE);share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriArrayList);share.setType("image/*");
// share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);context.startActivity(share);} else {Toast.makeText(context, "分享文件不存在", Toast.LENGTH_SHORT).show();}} catch (Exception e) {e.printStackTrace();}}
注意:红色代码就是导致二次分享无效的源头