从内容URI获取搜索图像的绝对文件路径 [英] Getting the Absolute File Path from Content URI for searched images
问题描述
我正在尝试使用隐式意图将其他应用程序中的图像共享到我的应用程序中 FileChooser 来获取其他类型的内容URI的文件路径(例如,从Gallery中获取).>
试图到处寻找,没有太多帮助. 有人可以建议如何使用这些内容URI吗?
如果您绝对需要文件的本地副本,则需要打开InputStream
将内容复制到您知道的本地文件中到达然后从那里走的路.旁注:番石榴的ByteStreams#copy
是实现此目的的简便方法.
当然,此文件不再受原始Uri源的支持,所以我认为这不是您想要的.相反,您应该使用Uri的预期API.看看存储访问框架
修改
以下是从Uri
InputStream
的方法
InputStream inputStream = getContentResolver().openInputStream(uri);
I am trying to share images from other applications to my application using implicit intent ACTION_SEND.
While sharing search images from chrome browser, app receives intent with a Content URI like this:
content://com.android.chrome.FileProvider/images/screenshot/1457448067808912906311.jpg
How can I fetch file path from this type of Content URI? All other apps like Facebook, Google+ are doing it. I am using FileChooser for getting file path of other types of Content URIs (eg. from Gallery).
Tried looking everywhere, without much help. Can someone suggest how to work with these Content URIs?
If you absolutely need a local copy of the file, you are going to need to open the InputStream
copy the contents to a local file that you know the path to and then go from there. Sidenote: Guava's ByteStreams#copy
is an easy way to accomplish this.
Of course this file is no longer backed by the original Uri source, so I don't think this is what you want. Instead, you should work with the Uri's intended API. Take a look at the Storage Access Framework
Edit
Here is how you can get an InputStream
from your Uri
InputStream inputStream = getContentResolver().openInputStream(uri);
这篇关于从内容URI获取搜索图像的绝对文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!