码迷,mamicode.com
首页 > 移动开发 > 详细

android 获取所有SD卡目录

时间:2017-10-20 11:56:49      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:dir   判断   ace   gem   排除   cto   sdi   irf   tor   

//返回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;
}

android 获取所有SD卡目录

标签:dir   判断   ace   gem   排除   cto   sdi   irf   tor   

原文地址:http://www.cnblogs.com/agilezhu/p/7698532.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!