Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: attaching file to mail

i have this code for sending mail:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
     startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
     Toast.makeText(BladeActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

how to attach to this mail the file: /sdcard/MyFile.csv

thanks,

like image 589
Gold Avatar asked Feb 20 '23 19:02

Gold


2 Answers

Try this:

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/MyFile.csv"));

And make sure you have required permissions to access external storage.

like image 63
fardjad Avatar answered Mar 07 '23 00:03

fardjad


use this code..

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+arr));
intent.setType("image/jpg"); 
startActivity(intent);
like image 44
Nitesh Khosla Avatar answered Mar 07 '23 01:03

Nitesh Khosla