安卓6.0如何获取外置sd卡路径

 时间:2026-02-14 20:02:19

1、直接使用如下方法即可:

2、private static String getStoragePath(Context mContext, boolean is_removale) {    

  

      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_removale == 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;  

}  

3、好啦,以上就是安卓6.0获取外置sd卡路径的方法,赶快去试试吧!

  • 忍者必须死3海滨·苍牙皮肤效果预览
  • 魔族2人刷黑脚boss攻略
  • 华为P9通过“HiSuite”将旧手机资料导入新手机
  • Wear OS怎么同步日历活动数据
  • QQ音乐智能曲谱怎么使用
  • 热门搜索
    如何补锌 人死后会去哪里 如何挽救爱情 宁波旅游局 如何瘦胳膊 溧阳天目湖旅游攻略 蟋蟀的耳朵长在哪里 白山旅游 心肌劳损是怎么回事 营业执照如何办理