博客
关于我
获取android的所有挂载路径(转)
阅读量:396 次
发布时间:2019-03-05

本文共 2316 字,大约阅读时间需要 7 分钟。

???????????????

?Android??????????????????????????????????????????????????????????????????

????????????????

????????????StorageManager????????????????????????????????????????????????????

?????
public static List
listAllStorage(Context context) { List
storages = new ArrayList<>(); StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); try { Method getVolumeList = StorageManager.class.getMethod("getVolumeList", new Class[0]); Object[] invokes = (Object[]) getVolumeList.invoke(storageManager, new Object[0]); for (int i = 0; i < invokes.length; i++) { Object obj = invokes[i]; Method getPath = obj.getClass().getMethod("getPath", new Class[0]); String path = (String) getPath.invoke(obj, new Object[0]); StorageInfo info = new StorageInfo(path); info.state = (String) getVolumeState.invoke(storageManager, path); info.isRemoveable = ((Boolean) obj.getClass().getMethod("isRemovable", new Class[0]).invoke(obj, new Object[0])).booleanValue(); if (info.state.equals(CommonUtil.MOUNTED)) { storages.add(info); } } } catch (Exception e) { e.printStackTrace(); } storages.trimToSize(); return storages;}
???
  • ?????????????????
  • ???????????????
???
  • ?????????????????????
  • ????????????

????????getVolumePaths??

??????????StorageManager?getVolumePaths?????????????????????????????????????????????????

?????
public static String[] getAllSdPaths(Context context) {    String[] paths = null;    StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);    try {        Method mMethodGetPaths = mStorageManager.getClass().getMethod("getVolumePaths");        paths = (String[]) mMethodGetPaths.invoke(mStorageManager);    } catch (Exception e) {        e.printStackTrace();    }    return paths;}
???
  • ??????????
  • ???????????
???
  • ?????????????????????????????????

??????

?? ??? ???
????? ??????????????? ???????
??? ???????????????? ?????????????
???? ????????????? ???????????
???? ??????StorageManager????????????? ??????getVolumePaths?????

????

  • ?????????????????????????????????
  • ??????????????????????????????????

???????????????????????????????????????????

转载地址:http://ebbzz.baihongyu.com/

你可能感兴趣的文章
pkpmbs 建设工程质量监督系统 文件上传漏洞复现
查看>>
pku 2400 Supervisor, Supervisee KM求最小权匹配+DFS回溯解集
查看>>
queue队列、deque双端队列和priority_queue优先队列
查看>>
PKUSC2018游记
查看>>
PK项目测试,做产品测试有这4大优势!
查看>>
pl sql 的目录 所在的目录 不能有 小括号,如 Program Files (x86)
查看>>
PL SQLDEVELOPMENT导出数据库脚本
查看>>
Queue
查看>>
PL/SQL Developer中文版下载以及使用图解(绿色版)
查看>>
pl/sql developer乱码,日期格式等问题解决
查看>>
PL/SQL 中的if elsif 练习
查看>>
PL/SQL 存储函数和过程
查看>>
query简单入门到精通细节 - (六)Jquery效果之“淡入与淡出”
查看>>
PL/SQL提示“ORA-01722:无效数字,将无效数字查找出来
查看>>
PL/sql语法单元
查看>>
PL/SQL连接远程服务器数据库,出现ORA-12154: TNS: 无法解析指定的连接标识符。
查看>>
pl/sql锁
查看>>
PL2303 Windows 10 驱动项目常见问题解决方案
查看>>
QueryPerformanceCounter与QueryPerformanceFrequency
查看>>
Plaid.com的监控系统如何实现与9600多家金融机构的集成
查看>>