Reputation: 2609
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?
Upvotes: 0
Views: 3616
Reputation: 128428
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();
}
Upvotes: 4