0

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

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Anmol Kohli
  • 33
  • 1
  • 6
  • https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it – CommonsWare Jan 27 '17 at 21:52
  • Yes I have tried providing the run time permissions.Also made sure in settings of permission was given still it return null pointer error – Anmol Kohli Jan 28 '17 at 10:46

0 Answers0