0

I have this email sending code that does not show a chooser (good). How can I extend it to include a file attachment, without involving a chooser?

// Based on http://stackoverflow.com/questions/3312438
final Intent intent = new Intent(Intent.ACTION_VIEW);
final Uri data = Uri.parse("mailto:user@domain.com?subject=My Sugbject&body=");
intent.setData(data);
startActivity(intent);
user1139880
  • 1,828
  • 3
  • 18
  • 27

3 Answers3

0

Try Following code,

Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("photo.jpg"));
startActivity(i);
Lucifer
  • 29,392
  • 25
  • 90
  • 143
0

try this :

Intent emailintent = new Intent(android.content.Intent.ACTION_SEND); 
emailintent.setType("image/jpeg");
emailintent.putExtra(android.content.Intent.EXTRA_TEXT, 
"email body here"); 
emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
    {"test@gmail.com"}); 
emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
"Subject here"); 
String filName="file:///sdcard/photos/estdemo.jpg";
emailintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ filName));
this.startActivity(emailintent);
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • Thanks Imran. Tried it but got a chooser with several options. My question was how to add an attachment without adding a chooser. – user1139880 Apr 03 '12 at 02:50
0

Use the below code to sent a mail

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("vnd.android.cursor.dir/email");
String to[] = "asd@gmail.com";
sharingIntent.putExtra(Intent.EXTRA_EMAIL, to);
sharingIntent.putExtra(Intent.EXTRA_STREAM,filePath);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"subject");
startActivity(Intent.createChooser(sharingIntent, "Send email"));
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • Thanks Agarawl. Tried your suggestion but am still getting a chooser with GMail, Skype and Google Docs. (had to changes it a little bit to work, added '{}' to the to literal and made filePath a file URI). – user1139880 Apr 03 '12 at 02:45