Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android\Intent: Send an email with image attachment

Tags:

android

email

The email is being received on by the recipient, but without the attachment. Here is the code, any expert knows where did I go wrong?

 Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);

String aEmailList[] = { "mymailgmail.com" };
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);

messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
...    
messageIntent.setType("image/jpeg");
File downloadedPic = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "MyApp.jpg");

messageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));

startActivity(Intent.createChooser(messageIntent, getResources().getString(R.string.chooser_pic)));

I get:

file:// attachment path must point to file://sdcard. Ignoring attachment file://...file name is MyApp.jpg

I am not getting image, only above text message. Thanks.

like image 760
Kumar Avatar asked Jan 22 '13 11:01

Kumar


2 Answers

Try below code...

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/Myimage.jpeg"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
like image 96
Mehul Ranpara Avatar answered Oct 04 '22 19:10

Mehul Ranpara


Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.setType("application/image");

Uri uri = Uri.parse("file://" + filepath);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);
like image 38
yteng Avatar answered Oct 04 '22 19:10

yteng