Java 如何在我的应用程序中获取从 Whats 应用程序聊天中选择的图像路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46362742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:19:44  来源:igfitidea点击:

How to Get Image Path in my App which is Selected from Whats app's Chat?

javaandroid.netandroid-intent

提问by dharam

i have demo application with image view and in this image view i need to set image from which selected from whats appChat, Currently i was getting Path of selected image i.e. content://com.whatsapp.provider.media/item/245429

我有带有图像视图的演示应用程序,在此图像视图中,我需要设置从whats 应用程序聊天中选择的图像,目前我正在获取所选图像的路径,即content://com.whatsapp.provider.media/item/245429

Does any idea to resolve this ? Thank You in Advance.

有什么想法可以解决这个问题吗?先感谢您。

回答by CommonsWare

There is no image path, as there is no requirement that this Uripoint to a file, let alone point to a file that you have direct filesystem access to.

没有图像路径,因为不需要它Uri指向文件,更不用说指向您可以直接访问文件系统的文件了。

Use an image-loading library (e.g., Glide, Picasso) and provide it the Urithat you get from WhatsApp. Those libraries know how to use ContentResolverand openInputStream()to read in the bytes associated with that content, convert those bytes into a Bitmapusing BitmapFactory.decodeStream(), and put the Bitmapinto your ImageView.

使用图像加载库(例如 Glide、Picasso)并提供Uri您从 WhatsApp 获得的图像。这些库知道如何使用ContentResolver,并openInputStream()在与该内容相关联的读取字节,这些字节转换为Bitmap使用BitmapFactory.decodeStream(),并把Bitmap到你ImageView