Sharing Multiple Files through Intent

suggest change

The String List passed as a parameter to the share() method contains the paths of all the files you want to share.

It loops through the paths, adds each one as a Uri, and starts an activity that accepts this type. Uri.fromFile throws FileUriExposedException on Android 7.0 and higher, and this intent does not add FLAG_GRANT_READ_URI_PERMISSION.

public static void share(AppCompatActivity context,List<String> paths) {

      if (paths == null || paths.size() == 0) {
          return;
      }
      ArrayList<Uri> uris = new ArrayList<>();
      Intent intent = new Intent();
      intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
      intent.setType("*/*");
      for (String path : paths) {
              File file = new File(path);
              uris.add(Uri.fromFile(file));
      }
      intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      context.startActivity(intent);
  }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents