开发者

How can i receive image from Gmail to my app in Android

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 imag开发者_开发百科e 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


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


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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜