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

San*_*ani 2 uri file android-file android-fileprovider

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

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Yyy*_*Yyy 6

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