I've been working on Android program to send email with an attachment (text/plain)using Intent
with Intent.ACTION_SEND
I used Intent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uri)
However, when I tried to have multiple files attached to the same mail by calling Intent.putExtra(android.content.Intent.EXTRA_STREAM, uri)
multiple times, it failed to work. None of the attachment show up in the email.Thanks in Advance
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
System.out.println(emailText+emailTo);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailText);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailTo});
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
try
{
for (String file : filePaths)
{
File fileIn = new File(context.getFilesDir(),file);
System.out.println(fileIn+"yes");
Uri u = Uri.fromFile(fileIn);
uris.add(u);
System.out.println(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}