利用反射去获取一些值,而不必事事用framework.jar StorageManager storageManager = (StorageManager) mContext.getApplicationContext() .getSystemService(Context.STORAGE_SERVICE); StorageVolume[] volumes =null; try { Class<?> c = Class.forName("android.os.storage.StorageManager"); Method getVolumeList = c.getMethod("getVolumeList"); volumes = (StorageVolume[])getVolumeList.invoke(storageManager); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } finally { }
for (StorageVolume item : volumes) { String state = item.getState(); if (state != null && state.equals(Environment.MEDIA_MOUNTED)) { try { Class<?> c = Class.forName("android.os.storage.StorageVolume"); Method getPathMethod = c.getMethod("getPath"); String path = (String) getPathMethod.invoke(item); String name = item.getDescription(mContext); bean.setFileName(name); bean.setPath(path); bean.setType(getStorage(path)); list.add(bean); parcel.recycle(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } finally { } }