/** * Get external sd card path using reflection * @param mContext * @param is_removable is external storage removable * @return */private static String getExternalStoragePath(Context mContext, boolean is_removable) { StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); Class<?> storageVolumeClazz = null; try { storageVolumeClazz = Class.forname("androID.os.storage.StorageVolume"); Method getVolumeList = mStorageManager.getClass().getmethod("getVolumeList"); Method getPath = storageVolumeClazz.getmethod("getPath"); Method isRemovable = storageVolumeClazz.getmethod("isRemovable"); Object result = getVolumeList.invoke(mStorageManager); final int length = Array.getLength(result); for (int i = 0; i < length; i++) { Object storageVolumeElement = Array.get(result, i); String path = (String) getPath.invoke(storageVolumeElement); boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement); if (is_removable == removable) { return path; } } } catch (ClassNotFoundException e) { e.printstacktrace(); } catch (InvocationTargetException e) { e.printstacktrace(); } catch (NoSuchMethodException e) { e.printstacktrace(); } catch (illegalaccessexception e) { e.printstacktrace(); } return null;}
参考: https://gist.github.com/Pauloluan/4bcecc086095bce28e22
总结以上是内存溢出为你收集整理的android获取外置SD卡路径全部内容,希望文章能够帮你解决android获取外置SD卡路径所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)