Send email with bitmap object as an attachment in Android?
Asked Answered
L

2

9

I want to send the bitmap as an attachment in the mail. The image is not stored in SDCARD or anywhere in the device. The bitmap object gets created at runtime and that should be sent as an attachment.

Locate answered 23/1, 2011 at 17:16 Comment(0)
F
9

Then, you must save the Bitmap to the SDCard, and then attach it to the email (I guess, you know how to do so).

Why is it necessary to save it to the SDCard? That's because the email app will have to read the file that it's going to be attached; thus, you have to pass the path and filename to the email client. As any other app, the email client can only access files stored in its own private directory or the SDCard.

Fortyfive answered 23/1, 2011 at 17:24 Comment(4)
Thanx for the information. Is there any way we can send the bitmap object directly and not by saving it to the sdcard? I do not want images to be accessible to other apps or to the user.Locate
You can delete the image after the email has been sent.Fortyfive
How do I come to know whether email has been sent or not? There is no startActivityForResult method for starting ACTION_SEND intent. Also, will it be possible to send attachment as html.Locate
There's no way to know whether the email client sent the email. You could then try to send the mail manually (take a look at the JavaMail lib). And... not sure what you mean by "send attachment as HTML"... you mean send the image inside the HTML of the body? If so, it's not possible.Fortyfive
P
4
/* Return Drawable Object from Specified imageUrl In Web

 @imageUrl : image Url in Web

 */

try {
/// Getting image from Web
    InputStream is = (InputStream) new URL(imageUrl).getContent();
    // storing image from stream
    drawable = Drawable.createFromStream(is, "srcName");
    is.close();
    // converting drawable object to Bitmap to store in content providers of Media
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    // Store image in Devise database to send image to mail
    String path = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
    Uri screenshotUri = Uri.parse(path);
    final Intent emailIntent1 = new Intent(     android.content.Intent.ACTION_SEND);
    emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent1.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    emailIntent1.setType("image/png");
    startActivity(Intent.createChooser(emailIntent1, "Send email using"));

}
catch(Exception e) { }
Payson answered 31/3, 2012 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.