gpt4 book ai didi

android - Intent.ACTION_GET_CONTENT 打开最近的文件,这给出了错误的 URI

转载 作者:太空宇宙 更新时间:2023-11-03 10:41:49 26 4
gpt4 key购买 nike

我正在使用 Intent.ACTION_GET_CONTENT 打开最近的文件。从最近的文件中选择项目会给出错误的 URI,但从文件管理器中选择相同的文件会给出可以由我的代码处理的正确 URI。

public static String getRealPathFromURI(Context context, Uri uri) {
String path;
if ("content".equals(uri.getScheme())) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
path = cursor.getString(idx);
cursor.close();
} else {
path = uri.getPath();
}

return path;
}

注意:当我从最近的文件中选择 PDF 时,uri.getPath() 的输出是 /document/... 但是从文件管理器中选择相同的文件是 .../emulated/...

注意从最近的文件中选择文件时的错误是

Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

最佳答案

问题是我的代码不处理 Android 的新布局存储 URI。如果你也遇到这个问题,请引用this link因为作者写了一个很棒的方法来获取每个 URI 的真实路径。

关于android - Intent.ACTION_GET_CONTENT 打开最近的文件,这给出了错误的 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32177227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com