Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I launch android's email activity with an attachment attached in the email?

Tags:

android

In my android, how can I launch android's compose email activity with an attachment attached?

like image 272
yinglcs Avatar asked Jan 22 '23 10:01

yinglcs


1 Answers

Just launch an intent with the following structure:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "the subject");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("the content"));
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/file.ext"));
startActivity(intent);

Notice that I'm using the complete path to the file: "file:///sdcard/file.ext". Also, take into account that you can share files that you have saved into the SDCard only (otherwise, the email client will ignore the file).

like image 170
Cristian Avatar answered Jan 29 '23 21:01

Cristian