Question

I've got an app that accepts images via "Preview images" in Gmail on Android

I have the Uri :

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

The Astro image viewer or Gallery can display the image very well

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

but I dont know how to use this Uri to display image in my app.

Help me please

Was it helpful?

Solution

Sorry about that last answer. I am a bit embarrassed there. But this should be more of what you are looking for. This exact code may or may not run but conceptually this is way I found it should work. Let me know if you have any issues.


//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){}
}

OTHER TIPS

This worked for me:

    if (uri.toString().startsWith("content://gmail")) { // special handling for gmail
        Bitmap b;
        InputStream stream = activity.getContentResolver().openInputStream(uri);
        b = BitmapFactory.decodeStream(stream);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top