Android Intent for sending email with attachment

JavaAndroidAndroid IntentAttachment

Java Problem Overview


> Possible Duplicate:
> Email from internal storage

The email is being received on by the recipient, but without the attachment. Here is the code, any expert knows where did I go wrong?

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL,	new String[] {"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
if (!file.exists() || !file.canRead()) {
    Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
    finish();
    return;
}
Uri uri = Uri.parse("file://" + file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send email..."));

I am not getting any toast message. Thanks.

Java Solutions


Solution 1 - Java

The file is probably not world readable.

EDIT: indeed. Try doing this:

Uri uri = Uri.parse("file://" + file.getAbsolutePath());

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMr JacksonView Question on Stackoverflow
Solution 1 - JavaFemiView Answer on Stackoverflow