Gets an example of the android4.0 version sdcard path

  • 2020-05-27 07:12:16
  • OfStack


@SuppressLint("NewApi")// You know, 
private File findSDCARD() {
 boolean b = Environment.MEDIA_MOUNTED.equals(Environment
   .getExternalStorageState());
 if (!b) return null;

    File extFile = Environment.getExternalStorageDirectory();
 File[] files = extFile.listFiles();
 if (files == null)
  return null;
 for (File f : files) {
  if (extFile.isDirectory()
    && f.canWrite()//sd card 1 It must be writable . If you remove this condition, you get a hidden system specific folder 
    && Math.abs(extFile.getTotalSpace() - f.getTotalSpace()) > 2 * 1024 * 1024) {
    // External storage has the same storage capacity as the unmounted storage of a subdirectory . The subdirectory is mounted . You have different storage capacities 
    //2 * 1024 * 1024  Is used to indicate the size of the storage capacity of two memory   Of course not   random 
   return f;
  }
 }
 return null;
}
        // call ,14 for android4.0
  if (Build.VERSION.SDK_INT >= 14) {
  File sd = findSDCARD(extFile);
  }


Related articles: