Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android DocumentFile invalid URI

i am trying to list files in external storage devices on my android 5.1 phone using DocumentFile

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


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

This code works fine but i want to do it like this;

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

DocumentFile documentFile = DocumentFile.fromTreeUri(getApplicationContext(), Uri.parse(rootPathURI));

but i get an exception like this:

W/System.err( 5157): java.lang.IllegalArgumentException: Invalid     URI:"file:/media/storage/sdcard1/data/example.externalstorage/files/"
like image 804
Tom Avatar asked Oct 19 '22 05:10

Tom


1 Answers

fromTreeUri() is for use with a Uri returned from an ACTION_OPEN_DOCUMENT_TREE request, as is noted in the documentation. It might work for a StorageVolumeUri`.

like image 198
CommonsWare Avatar answered Oct 29 '22 18:10

CommonsWare