0

I get an image from a PHP server as a string (this image), and I want to send this image by e-mail as a attachment.

When I try to send e-mail, then the attachment is papers but only plain text is displaying at the receiver end. How do I send the e-mail correctly?

This is my code:

Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
String img_source = listBuzzInfoBean.get(photo).getBuzzImage();
File downloadedPic = new File(Environment.getExternalStorageDirectory(), img_source + ".jpg");// Art_Nature

Log.d("++++++++++++++", img_source);
Uri myUri = Uri.fromFile(downloadedPic);
picMessageIntent.putExtra(Intent.EXTRA_STREAM, myUri); //screenshotUri
startActivity(Intent.createChooser(picMessageIntent, "Share image using"));
cha0site
  • 10,517
  • 3
  • 33
  • 51
Murali Rao
  • 29
  • 1
  • 6

1 Answers1

0

I used the following code to handle this. I have noticed that differences between Gmail/Mail apps and how they handle this intent.

Also this post seems to have a similar problem. Android: Intent.ACTION_SEND with EXTRA_STREAM doesn't attach any image when choosing Gmail app on htc Hero

public static Intent createEmailWithAttachmentIntent(String[] addresses,
        String[] ccAddresses, String subject, String contentType,
        String filename, String messageBody) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.putExtra(Intent.EXTRA_EMAIL, addresses);
    i.setType(contentType);
    if(filename != null && !filename.equals(""))
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename)));
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, messageBody);

    if (ccAddresses != null && ccAddresses.length > 0)
        i.putExtra(Intent.EXTRA_CC, ccAddresses);
    return i;
}
Community
  • 1
  • 1
Evan Anger
  • 712
  • 1
  • 5
  • 24