android 获取所有SD卡目录

【android 获取所有SD卡目录】历览千载书,时时见遗烈。这篇文章主要讲述android 获取所有SD卡目录相关的知识,希望能为你提供帮助。

//返回sd卡路径
public static List< String> getStorageDirectories(Context context) {
StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
List< String> pathList = new ArrayList< > ();
File exDirFile = Environment.getExternalStorageDirectory();
String externalStorageDir = "";
if (exDirFile != null) {
externalStorageDir = exDirFile.getAbsolutePath();
}
try {
String[] paths = (String[]) sm.getClass().getMethod("getVolumePaths", null).invoke(sm, null);
if (paths != null & & paths.length > 0) {
for (String path : paths) {
File file = new File(path);
if (!TextUtils.isEmpty(path) & & !path.equalsIgnoreCase(externalStorageDir) & & file.isDirectory()) {
//判断是否目录,并排除系统虚拟出来的目录
pathList.add(path);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

return pathList;
}



























    推荐阅读