2016-07-26 105 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