android获取外置SD卡路径

android获取外置SD卡路径,第1张

概述/***Getexternalsdcardpathusingreflection*@parammContext*@paramis_removableisexternalstorageremovable*@return*/privatestaticStringgetExternalStoragePath(ContextmContext,booleanis_removable){StorageManagermStorageMa
/** * 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卡路径所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1055436.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存