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/"
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 StorageVolume
Uri`.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With