android - 从通过 FileProvider 创建的 Uri 获取文件路径

标签 android uri android-fileprovider

我使用此方法从 Uri https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java#L257 获取文件路径

但是当我传递如下创建的 Uri 时它抛出异常(“_data”列未找到):

public static Uri uriFromFile(Context context, String path) {
    if (path == null) return null;
    return FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", new File(path));
}

我只需要在我的 Activity 之间传递文件路径..

最佳答案

I use this method for getting file path from Uri

这是一种不可靠的方法,仅适用于少量的 Uri 值。

But it throw exception ("_data" column not found) when I pass Uri created such as below:

当然。对于大多数 Uri 值源,该代码将失败。

Get file path from Uri created via FileProvider

在这种特定情况下,您已经知道“文件路径”。它由代码段中名为 path 的变量表示。

更一般地说,您无法获得 Uri 的“文件路径”,原因很简单,因为不要求 Uri 指向文件,让一个你可以访问的。使用 ContentResolver 和类似 openInputStream() 的方法来访问 Uri 表示的内容。

关于android - 从通过 FileProvider 创建的 Uri 获取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39962385/

相关文章:

java - 这个 URI URL 有什么问题? IllegalArgumentException,非法字符

java - 文件未找到异常 :/storage/emulated/0/JsonParseTutorialCache: open failed: ENOENT (No such file or directory)

android - 使用函数 gethostbyname 将 C 编译为静态链接错误

android - 设置图像位图在 android marshmallow 中不起作用

asp.net - 在 asp.net 中确定网站的绝对、完全限定 url

java - 如何从 URI 字符串中以整数形式获取图像位置

android - 如何从 whatsapp fileprovider 获取 txt 文件

android - 错误找不到符号变量 FileProvider 包 android.support.v4.content 不存在

android - 在 Nougat 上使用 Scoped Directory Access 捕获图像

android - 尝试调用接口(interface)方法 'void android.support.v7.widget.DecorContentParent.setWindowCallback(android.view.Window$Callback)'