I am trying to read all the files from the sd card. It works for emulator below api 23 but doesnt work for the same and above. Whenever I call method listFiles
it gives a null pointer error.
I've provided runtime permissions, made sure permission is given from settings as well, I've tried to check if anyhow I can read or write from the storage both of the following methods return false
/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) ||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
Any suggestions what could be the problem while I've also tried to mount and unmount from adb shell but I get permission denied. I have also tried to create and sdcard by using mksdcard but when I edit the path to the sd card in avd manager nothing happens and the studio gets stuck