安卓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卡路径的方法,赶快去试试吧!

© 2026 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com