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

你可能感兴趣的文章
ollama本地部署DeepSeek(Window图文说明)
查看>>
ollama运行多模态模型如何进行api测试?
查看>>
OMG,此神器可一次定一周的外卖
查看>>
Omi 多端开发之 - omip 适配 h5 原理揭秘
查看>>
On Error GOTO的好处
查看>>
onclick事件的基本操作
查看>>
oncopy和onpaste
查看>>
onCreate中的savedInstanceState作用
查看>>
onCreate()方法中的参数Bundle savedInstanceState 的意义用法
查看>>
One good websit for c#
查看>>
OneASP 安全公开课,深圳站, Come Here, Feel Safe!
查看>>
OneBlog Shiro 反序列化漏洞复现
查看>>
one_day_one--mkdir
查看>>
ONI文件生成与读取
查看>>
Online PDF to PNG、JPEG、WEBP、 TXT - toolfk
查看>>
onlstm时间复杂度_CRF和LSTM 模型在序列标注上的优劣?
查看>>
onlyoffice新版5.1.2版解决中文汉字输入重复等问题
查看>>
onnx导出动态输入
查看>>
onnx导出动态输入
查看>>
onScrollStateChanged无效
查看>>