我需要帮助来获取我们通过Intent从downloads文件夹或任何其他文件夹中选择的内容的文件路径。
我要附加一个我一直在使用的fileUtil类,在Nougat版本之前,它都可以正常工作。但是对于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/

10-11 22:34
查看更多