Using the code below, I can attach files to an email from my application with no problem - if I use the Gmail application as my email client. However, any other email client disregards the attachment I send to it.
Here is my code:
public static void sendEmail(Context context, String toAddress, String subject, String body, String attachmentPath) throws Exception{
try {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", toAddress, null));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
File file = new File(attachmentPath);
Uri uri = Uri.fromFile(file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(intent);
}
catch(Exception ex) {
ex.printStackTrace();
throw ex;
}
}
Does anyone know how to set up an Intent in such a way that any non-Gmail email client will recognize and accept an attachment?
Thank you.