【问题标题】:How can i receive image from Gmail to my app in Android我如何从 Gmail 接收图像到我在 Android 中的应用程序
【发布时间】:2011-03-07 14:39:40
【问题描述】:

我有一个应用可以通过 Android 版 Gmail 中的“预览图片”接受图片

我有 Uri :

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

Astro 图​​像查看器或图库可以很好地显示图像

我可以使用 URI:content://media/external/images/media/79

但我不知道如何使用此 Uri 在我的应用中显示图像。

请帮帮我

【问题讨论】:

    标签: android image uri gallery astro


    【解决方案1】:

    对最后一个答案感到抱歉。我在那里有点尴尬。 但这应该是您正在寻找的更多内容。这个确切的代码可能会运行也可能不会运行,但从概念上讲,这是我发现它应该工作的方式。如果您有任何问题,请告诉我。

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

    【讨论】:

    • 对此感到抱歉。出于某种原因,我在考虑 url。希望这对您更有帮助。
    • 感谢您的评论,我通过下载附件文件解决了我的问题,然后显示它
    • 这个解决方案对我不起作用。在创建文件的行,我得到一个异常:“java.lang.IllegalArgumentException:URI 中的预期文件方案:content://gmail-ls/messages//20/attachments/0.1/SIMPLE/假”
    【解决方案2】:

    这对我有用:

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

    【讨论】:

      猜你喜欢
      • 2021-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-01
      • 1970-01-01
      • 2014-09-01
      相关资源
      最近更新 更多