2016-07-26 102 views
2

我试图列出使用DocumentFile的Android DocumentFile无效的URI

String rootPathURI = "file:/media/storage/sdcard1/data/example.externalstorage/files/"; 


File f = new File(URI(rootPathURI)); 
DocumentFile documentFile = DocumentFile.fromFile(f); 

此代码工作正常我的Android 5.1手机在外部存储设备中的文件,但我想这样做这样的;

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/" 

回答

1

fromTreeUri()是与从ACTION_OPEN_DOCUMENT_TREE请求返回一个Uri使用,如the documentation指出。它可能工作StorageVolume Uri`。

+0

你能给我一个StoreVolume Uri的例子吗? – Tom