本文共 2348 字,大约阅读时间需要 7 分钟。
?Android??????????????????????????????????????????????????????????????????
????????????StorageManager????????????????????????????????????????????????????
public static ListlistAllStorage(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;}
??????????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/