博客
关于我
获取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/

你可能感兴趣的文章
Objective-C实现fibonacci search斐波那契查找算法(附完整源码)
查看>>
Objective-C实现fibonacci斐波那契算法(附完整源码)
查看>>
Objective-C实现fibonacci斐波那契算法(附完整源码)
查看>>
Objective-C实现FIFO(附完整源码)
查看>>
Objective-C实现FigurateNumber垛积数算法(附完整源码)
查看>>
Objective-C实现finding bridges寻找桥梁算法(附完整源码)
查看>>
Objective-C实现first come first served先到先得算法(附完整源码)
查看>>
Objective-C实现fischer yates shuffle洗牌算法(附完整源码)
查看>>
Objective-C实现fisherYates洗牌算法(附完整源码)
查看>>
Objective-C实现FTP文件上传(附完整源码)
查看>>
Objective-C实现fuzzy operations模糊运算算法(附完整源码)
查看>>
Objective-C实现Gale-Shapley盖尔-沙普利算法(附完整源码)
查看>>
Objective-C实现gamma recursive伽玛递归算法(附完整源码)
查看>>
Objective-C实现getline函数功能(附完整源码)
查看>>
Objective-C实现gnome sortt侏儒排序算法(附完整源码)
查看>>
Objective-C实现GraphVertex图顶点算法(附完整源码)
查看>>
Objective-C实现greatest common divisor最大公约数算法(附完整源码)
查看>>
Objective-C实现greedy coin change贪心硬币找零算法(附完整源码)
查看>>
Objective-C实现half adder半加器算法(附完整源码)
查看>>
Objective-C实现hamiltonianCycle哈密尔顿图算法(附完整源码)
查看>>