How can I get an image from Gmail in my Android application

I have an application that accepts images through "Image Preview" in Gmail on Android

I have Uri:

Content: // gmail-ls / messages / my_gmail_id_ @ _gmail.com/65/attachments/0.1/SIMPLE/false

Astro Image Viewer or Gallery can display an image very well.

I can use URI: content: // media / external / images / media / 79

but I don’t know how to use this Uri to display the image in my application.

help me please

+3
source share
2 answers

. . , . , , , . , .


//Get your uri
Uri mAndroidUri = Uri.parse("content://gmail-ls/messages/my_gmail_id_@_gmail.com/65/attachments/0.1/SIMPLE/false");
ImageView iv = new ImageView(context);

try{
    //converts android uri to java uri then from that to file
    //after converting to file you should be able to manipulate it in anyway you like. 
    File mFile = new File(new URI(mAndroidUri.toString()));

    Bitmap bmp = BitmapFactory.decodeStream(mFile);
    if (null != bmp)
        iv.setImageBitmap(bmp);
    else
        System.out.println("The Bitmap is NULL");

    }catch(Exception e){}
}

+2

:

    if (uri.toString().startsWith("content://gmail")) { // special handling for gmail
        Bitmap b;
        InputStream stream = activity.getContentResolver().openInputStream(uri);
        b = BitmapFactory.decodeStream(stream);
    }
+1

All Articles