从内容URI获取搜索图像的绝对文件路径 [英] Getting the Absolute File Path from Content URI for searched images

查看:517
本文介绍了从内容URI获取搜索图像的绝对文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用隐式意图将其他应用程序中的图像共享到我的应用程序中 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆