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

2025-05-18 10:03:10

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

2、privatestaticStringgetStoragePath(ContextmContext,booleanis_removale){StorageManagermStorageManager=(StorageManager)mContext.getSystemService(Context.STORAGE_SERVICE);Class<?>storageVolumeClazz=null;try{storageVolumeClazz=Class.forName("android.os.storage.StorageVolume");MethodgetVolumeList=mStorageManager.getClass().getMethod("getVolumeList");MethodgetPath=storageVolumeClazz.getMethod("getPath");MethodisRemovable=storageVolumeClazz.getMethod("isRemovable");Objectresult=getVolumeList.invoke(mStorageManager);finalintlength=Array.getLength(result);for(inti=0;i<length;i++){ObjectstorageVolumeElement=Array.get(result,i);Stringpath=(String)getPath.invoke(storageVolumeElement);booleanremovable=(Boolean)isRemovable.invoke(storageVolumeElement);if(is_removale==removable){returnpath;}}}catch(ClassNotFoundExceptione){e.printStackTrace();}catch(InvocationTargetExceptione){e.printStackTrace();}catch(NoSuchMethodExceptione){e.printStackTrace();}catch(IllegalAccessExceptione){e.printStackTrace();}returnnull;}

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

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢