Android multiple email attachments using Intent Android multiple email attachments using Intent android android

Android multiple email attachments using Intent


Here is the code you need to create an emailIntent that contains multiple attachments.

public static void email(Context context, String emailTo, String emailCC,    String subject, String emailText, List<String> filePaths){    //need to "send multiple" to get more than one attachment    final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);    emailIntent.setType("text/plain");    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,         new String[]{emailTo});    emailIntent.putExtra(android.content.Intent.EXTRA_CC,         new String[]{emailCC});    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);     emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);    //has to be an ArrayList    ArrayList<Uri> uris = new ArrayList<Uri>();    //convert from paths to Android friendly Parcelable Uri's    for (String file : filePaths)    {        File fileIn = new File(file);        Uri u = Uri.fromFile(fileIn);        uris.add(u);    }    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));}


ACTION_SEND_MULTIPLE should be the action

and then emailIntent.setType("text/plain");

followed by:

ArrayList<Uri> uris = new ArrayList<Uri>();String[] filePaths = new String[] {"sdcard/sample.png", "sdcard/sample.png"};for (String file : filePaths){    File fileIn = new File(file);    Uri u = Uri.fromFile(fileIn);    uris.add(u);}emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);startActivity(emailIntent);

This works for me.


Although this is an old thread, but as it is shown on top on google searches i want to add a small hint to make it complete, hence I stumpled upon it.

It is necessary to make the attached files readable for the mail activity, otherwise they will not be attached. So you have to call somewhere

fileIn.setReadable(true, false)