I know there's a lot of questions similar with my issues but none of the answers able fixed my problem.
Please know that on Android 6 below (<6) everything works as expected I can create file into the USB directory. With the same set of "codes" it fails in Android 6. The problem is that the File.canWrite() returns "false" in Android 6 for USB directory.
Here how I list down the "valid" folders/directories:
File rootDir = new File(Environment.getRootDirectory().toString());
List<File> folders = new ArrayList<>();
File[] files = rootDir.listFiles();
for (File file : files) {
if (isValidDirectory(file) || file.equals(mInitialRoot)) {
folders.add(file);
}
}
And this is the isValidDirectory() method do:
private boolean isValidDirectory(File file) {
return file.isDirectory()
&& file.canWrite()
&& file.canRead()
&& file.exists();
}
I don't know why but the file.canWrite() returns "false" on android 6 thus make the isValidDirectory() to returns "false"
I already added the android.permission.WRITE_EXTERNAL_STORAGE
and most of the answers I found are pointing on this permission and since I already declared it I'm not sure where the problem is...
Any help is appreciated thanks in advance.