/**
* 获取外置SD卡路径
*
*/
public String[] getExtSDCardPath() {
StorageManager storageManager = (StorageManager) getActivity().getSystemService(Context
.STORAGE_SERVICE);
try {
Class<?>[] paramClasses = {};
Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths", paramClasses);
getVolumePathsMethod.setAccessible(true);
Object[] params = {};
Object invoke = getVolumePathsMethod.invoke(storageManager, params);
return (String[])invoke;
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
返回的String[]数组中,string[0]为内置sd卡路径;string[1]为外置sd卡路径。
转载来源:https://www.jianshu.com/p/1a50c26c6ca9