我正在尝试使用DocumentFile在我的Android 5.1手机上列出外部存储设备中的文件。
String rootPathURI = "file:/media/storage/sdcard1/data/example.externalstorage/files/";
File f = new File(URI(rootPathURI));
DocumentFile documentFile = DocumentFile.fromFile(f);
这段代码可行,但我想按照以下方式处理:
String rootPathURI = "file:/media/storage/sdcard1/data/example.externalstorage/files/";
DocumentFile documentFile = DocumentFile.fromTreeUri(getApplicationContext(), Uri.parse(rootPathURI));
但我遇到了这样的异常:
W/System.err( 5157): java.lang.IllegalArgumentException: Invalid URI:"file:/media/storage/sdcard1/data/example.externalstorage/files/"