In my application, I want to be able to send email. I am able to send email with text. However, I want to add attach file or photo from device memory in email. Does anybody have any ideas on how can I do this?
Asked
Active
Viewed 3,606 times
1 Answers
4
Here is the demo of doing "Email with file attachment".
Note: Below code is taking file stored inside your sd-card and add as an attachment to the email.
try
{
String fileName = URLEncoder.encode(yourfilename, "UTF-8");
String PATH = Environment.getExternalStorageDirectory()+"/"+fileName.trim().toString();
Uri uri = Uri.parse("file://"+PATH);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, "");
i.putExtra(Intent.EXTRA_SUBJECT,"android - email with attachment");
i.putExtra(Intent.EXTRA_TEXT,"");
i.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(i, "Select application"));
}
catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

Paresh Mayani
- 127,700
- 71
- 241
- 295
-
It is not working when i am sending the email again with same subject – Deepak Goel Jan 24 '14 at 06:41