0

I have to following problem:

I want to send an email with an image attached to it. I wrote this code:

    File file = context.getDir("Files", context.MODE_WORLD_WRITEABLE);
    File image = new File(file, "image.jpg");

    Uri U = Uri.fromFile(image);
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("image/jpg");
    i.putExtra(Intent.EXTRA_STREAM, U);
    context.startActivity(Intent.createChooser(i, "Email:"));

The email is sent but there is no attachment.

Does anybody have any idea why the email is sent without the attachment?

EDIT

I have found the answer to my question. Because the image was stored on the internal storage, it did not have enough rights so it could not be sent via email. I've moved my image to externalStorage and now it's working :)

Thanks, Ark

Aurelian Cotuna
  • 3,076
  • 3
  • 29
  • 49

2 Answers2

1

Try this one -

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Test");
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths)
{
    File fileIn = new File(file);
    Uri u = Uri.fromFile(fileIn);
    uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(emailIntent);

Just see my Existing Answer also

Community
  • 1
  • 1
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
  • I have tried both answers and noone worked for me. I can see the file being attached to email before I send it, but it never gets to my inbox with the attachment inside – Aurelian Cotuna Jun 11 '12 at 20:27
1
String smsBody = "Body of the Content";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject of the Mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, smsBody);
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile("mnt/sdCard/SampleImageFloder/TestImage.png"));
emailIntent.setType("vnd.android.cursor.dir/email");
activity.startActivity(Intent.createChooser(emailIntent,"Email:"));
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Aerrow
  • 12,086
  • 10
  • 56
  • 90
  • I have tried both answers and noone worked for me. I can see the file being attached to email before I send it, but it never gets to my inbox with the attachment inside – Aurelian Cotuna Jun 11 '12 at 20:28