I want to browse all the files on a device looking for all the files ending with a specific file extension. If i dont have access to a specific folder that is fine i want to skip and continue to the next... i have the code to do just that Files.walkTree and File.list() the problem is I am getting accessdeniedexception and File.list returns null. So my question in Java how do you search the device for files ending with a given extension.
Please note: I have the code runnning properly on my PC the same code is not running on my device or emulator
File f = Paths.get("/storage/self/primary/").toFile();
String files [] =f.list();
if (files!=null) {
Log.v(LOG_TAG,"clickRefresh..files array not null.."+files.length);
// For each pathname in the pathnames array
for (String pathname : files) {
// Print the names of files and directories
Log.v(LOG_TAG, "list=" + pathname);
}
}
else{
Log.v(LOG_TAG,"clickRefresh..so the files is null...");
}
The code above returns a null pathnames..and also the code below doesn't work on device or emulator but its fine on my PC (minus the Log.v )
Files.walkFileTree(source, new MyFileVisitor());
The below contains my permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>