Android 获取SD卡根目录方法
作者:互联网
获取SD卡根目录,兼容Android10及以上版本的方法
public File getRootFile(Context context) { File file; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // /storage/emulated/0/Android/data/com.example.demo/files File externalFileDir = context.getExternalFilesDir(null); do { externalFileDir = Objects.requireNonNull(externalFileDir).getParentFile(); } while(Objects.requireNonNull(externalFileDir).getAbsolutePath().contains("/Android")); file = Objects.requireNonNull(externalFileDir); } else { file = new File(Environment.getExternalStorageDirectory().getAbsoluteFile().toURI()); } return file; }
标签:file,Objects,File,externalFileDir,根目录,Android,requireNonNull,SD 来源: https://www.cnblogs.com/swalka/p/16394814.html