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

你可能感兴趣的文章
php 特定时间段统计,jpgraph某个时间段的数据统计
查看>>
php 生成csv mac下乱码
查看>>
php 生成证书 签名及验签
查看>>
php 的rsa加密与解密
查看>>
PHP 的标准输入与输出
查看>>
php 笔记 (早前的,很乱)
查看>>
PHP 第一天
查看>>
Redis使用量暴增,快速定位有哪些大key在作怪
查看>>
php 结课作业答案,北语201803考试批次《PHP》(结课作业)1.pdf
查看>>
PHP 统计数据功能 有感
查看>>
SpringBoot处理JSON数据
查看>>
Redis使用基本套路
查看>>
php 解决项目中多个自动加载冲突问题
查看>>
PHP 设置调试工具XDebug PHPStorm IDE
查看>>
php 身份证号检测
查看>>
PHP 输入输出流合集
查看>>
PHP 过滤器(Filter)
查看>>
php 运算符and or && || 的详解
查看>>
php 返回html字符串长度限制,记一次js中和php中的字符串长度计算截取的终极问题和完美...
查看>>
php 阿里云oss 上传回调
查看>>