file - 无法获取用于从 Android 中的 MI-Oreo(MI-A2)设备的下载文件夹中选择任何文件的 URI

标签 file uri android-file android-fileprovider

我需要帮助来获取我们通过 Intent 从下载文件夹或任何其他文件夹中选择的内容的文件路径。 我附上 fileUtil我一直在使用的类,它在牛轧糖版本之前运行良好。但是对于 oreo 以及在某些特定设备中也是如此,我们收到一个空路径作为返回。因此,如果有人遇到过此类错误并找到了解决方案,请在此处分享。

if(resultCode ==RESULT_OK)
{
    final Uri uri = data.getData();
    // Get the File path from the Uri
    String path = FileUtils.getPath(this, uri);
    // Alternatively, use FileUtils.getFile(Context, Uri)
    if (path != null && FileUtils.isLocal(path)) {
        //File file = new File(path);
        this.file = new File(path);
        profile_imagepath = path;
        filename = file.getName();
        txtselectedfile.setText(filename);
    }
}

最佳答案

你可以尝试使用ACTION_PICK对于 26 以上的 api 级别来解决此问题,而不是使用 ACTION_GET_CONTENT . 尝试并希望这对您有所帮助。

关于file - 无法获取用于从 Android 中的 MI-Oreo(MI-A2)设备的下载文件夹中选择任何文件的 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52658893/

相关文章:

Android 写入具有错误权限的文件

java - File.exists() 方法总是返回 true,即使文件不存在

mysql - MySQL查询缓存文件保存在哪里?

java - 当多行作为 JTextarea 的输入时,如何在文件中写入多行?

java - 尝试从 URI 获取文件名时出现致命的运行时异常

java - 如何从 ACTION_GET_CONTENT Intent 获取的 URI 中获取文件名?

android - nginx 从 Web 重定向到移动应用程序

python - 将 numpy.random.get_state() 写入文件

file - 在 Matlab 中检查文件是否打开

android - 不使用 AssetManager 从资源加载文件