Attaching Files In Email In Android Java

Opening the email application from java can be done like the following:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
//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);
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

To change the subject of the email, simple change the string in EXTRA_SUBJECT. You can change the other variables likewise.

Posted in Android, Tips and Tricks Tagged with: , ,