volume.setRemovable((boolean) volumeList[i].getClass().getMethod(“isRemovable”).invoke(volumeList[i]));
volume.setState((String) volumeList[i].getClass().getMethod(“getState”).invoke(volumeList[i]));
list_storagevolume.add(volume);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
} else {
LogUtils.D(“null-------------------------------------”);
}
} catch (Exception e1) {
e1.printStackTrace();
}
return list_storagevolume;
}
通过反射调用获取内置存储和外置sd卡根路径(通用)
/**
-
通过反射调用获取内置存储和外置sd卡根路径(通用)
-
@param mContext 上下文
-
@param is_removale 是否可移除,false返回内部存储,true返回外置sd卡
-
@return
*/
private static String getStoragePath(Context mContext, boolean is_removale) {
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
Class<?> storageVolumeClazz = null;
String path="";
try {
storageVolumeClazz = Class.forName(“android.os.storage.StorageVolume”);
Method getVolumeList = mStorageManager.getClass().getMethod(“getVolumeList”);
Method getPath = storageVolumeClazz.getMethod(“getPath”);
Method isRemovabl