Send email with multiple attachments

I am trying to send an email with multiple attachments.

Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {" email1@email.com ", " email2@email.com "}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject"); emailIntent.putExtra(Intent.EXTRA_TEXT, "The Text"); emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); emailIntent.setType("text/plain"); startActivity( Intent.createChooser(emailIntent, "Send Email Using: ") ); 

This works great when I send an email using gmail, but it does not attach attachments if I send an email using an email client on Nexus One. It has all the text, a theme, etc., but no attachments. I have an email account if that matters ...

+6
android android-intent email attachment
source share
2 answers

Try this job perfectly.

 final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType("plain/text"); ArrayList<Uri> uris = new ArrayList<Uri>(); String[] filePaths = new String[] {image1 Path,image2 path}; for (String file : filePaths) { File fileIn = new File(file); Uri u = Uri.fromFile(fileIn); uris.add(u); } if ( !(app_preferences.getString("email", "") == null || app_preferences.getString("email", "").equals(""))) { emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {app_preferences.getString("email", "")}); } emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject name"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Please find the attachment."); emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(emailIntent, "Email:")); 
+12
source share

I tried it all a million times - made it work, but had an unpleasant warning. Found an Android error. There is a fix and additional information:

 https://code.google.com/p/android/issues/detail?id=38303 Error: ClassCastException warning in log when opening e-mail app with a body and multiple file attachments. 

Update: A workaround was found. Instead

 sendIntent.putExtra(Intent.EXTRA_TEXT, "See attached CSV files."); 

Put the text as an ArrayList

 ArrayList<String> extra_text = new ArrayList<String>(); extra_text.add("See attached CSV files."); sendIntent.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text); 

Voila! More exceptions, and EXTRA_TEXT ends up as the body of the letter.

EDIT: I think just commenting on this line gets rid of the error - but then you cannot enter any information for the body. In my case, this is normal as I only send log files by email. Delete this line to get rid of the warning: 'sendIntent.putExtra (Intent.EXTRA_TEXT, "See Attached CSV Files.");'

0
source share

All Articles