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

本文共 2348 字,大约阅读时间需要 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实现isPowerOfTwo算法(附完整源码)
查看>>
Objective-C实现isupper函数功能(附完整源码)
查看>>
Objective-C实现ItemCF算法(附完整源码)
查看>>
Objective-C实现ItemCF算法(附完整源码)
查看>>
Objective-C实现iterating through submasks遍历子掩码算法(附完整源码)
查看>>
Objective-C实现iterative merge sort迭代归并排序算法(附完整源码)
查看>>
Objective-C实现jaccard similarity相似度无平方因子数算法(附完整源码)
查看>>
Objective-C实现Julia集算法(附完整源码)
查看>>
Objective-C实现jump search跳转搜索算法(附完整源码)
查看>>
Objective-C实现jumpSearch跳转搜索算法(附完整源码)
查看>>
Objective-C实现k nearest neighbours k最近邻分类算法(附完整源码)
查看>>
Objective-C实现k-means clustering均值聚类算法(附完整源码)
查看>>
Objective-C实现k-Means算法(附完整源码)
查看>>
Objective-C实现k-nearest算法(附完整源码)
查看>>
Objective-C实现KadaneAlgo计算给定数组的最大连续子数组和算法(附完整源码)
查看>>
Objective-C实现kadanes卡达内斯算法(附完整源码)
查看>>
Objective-C实现kahns algorithm卡恩算法(附完整源码)
查看>>
Objective-C实现karatsuba大数相乘算法(附完整源码)
查看>>
Objective-C实现karger算法(附完整源码)
查看>>
Objective-C实现KMP搜索算法(附完整源码)
查看>>