Kgrover
Kgrover

Reputation: 2116

How to attach Bitmap to email android

I have a bitmap that I have saved in the external storage. I already have a method that loads and returns the bitmap. My question is, how do I attach this image to an email Intent.

Note: I know how to start the email intent, I simply need to know how to attach the bitmap. Thanks.

This is how I am saving the pic:

private void savePicture(String filename, Bitmap b, Context ctx) {
    try {
        FileOutputStream out;
        out = ctx.openFileOutput(filename, Context.MODE_WORLD_READABLE);

        b.compress(Bitmap.CompressFormat.JPEG, 40, out);
        if (b.compress(Bitmap.CompressFormat.JPEG, 40, out) == true)
            out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 3

Views: 4364

Answers (1)

Niranj Patel
Niranj Patel

Reputation: 33248

try this for Attach Image with Email

Fetch Image From SdCard

String path = Environment.getExternalStorageDirectory().toString();     
File file = new File(path,"YourImageName.JPEG");
Uri pngUri = Uri.fromFile(file);

Email Intent

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);

Upvotes: 3

Related Questions