android 获取所有SD卡目录
2024-09-03 18:09:21
//返回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;
}
最新文章
- Spring整合log4j
- SpringMVC学习系列(3) 之 URL请求到Action的映射规则
- struts2学习笔记之四:多配置文件支持和常用配置参数
- http://www.open-open.com/lib/view/open1397274257325.html
- storyboard中xib文件不加载问题
- UNICODE字符串与多字节字符串的转换
- 内存/硬盘/io关系
- Locust性能测试工具的安装及实际应用
- [物理学与PDEs]第1章第5节 Maxwell 方程组的数学结构, 电磁场的波动性 5.3 电磁场的波动性, 自由电磁波
- Windows系统Nessus离线(Offline) 版的安装
- C. Brutality Educational Codeforces Round 59 (Rated for Div. 2) 贪心+思维
- SQL常见问题积累
- Context namespace element &#39;annotation-config&#39; and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
- 1.网站应用程序 - 《APS.NET本质论》
- IntelliJ IDEA删除代码的注释
- Django学习---抽屉热搜榜分析【all】
- Python实例---FTP小程序
- Linux进程间通信的几种方式总结--linux内核剖析(七)
- css 自定义滚动条
- BZOJ2668 [cqoi2012]交换棋子 【费用流】
热门文章
- python基礎學習第二天
- 剑指offer-面试题49-丑数-空间换时间
- 安装MongoDB到CentOS(YUM)
- Qt读写文件
- TTradmin v2.1 【2019年12月12日更新】简单好用的临时远程协助软件
- 获取http://XX.XX.XX.XX :XXXX/QuestionResult.aspx?method=接口返回值
- Python第三方库requests的编码问题
- Flink架构,源码及debug
- 产生随机数(rand()函数和srand()函数)
- win10中安装与配置maven