android 获取sdcard路径,解决默认获取内置内存卡路径

来源:互联网 发布:java实现ping功能 编辑:程序博客网 时间:2024/06/05 07:20

今天做项目遇到一点,需要获取sdcard,但路径如果写 Environment.getExternalStorageDirectory().getPath()


获取的是内置内存卡的路径,最好的解决方法是:


private String rootPath = "";
if(Environment.getExternalStorageDirectory().getParentFile()==null){<span style="white-space:pre"></span>rootPath=Environment.getExternalStorageDirectory().getPath();<span style="white-space:pre"></span>}else{<span style="white-space:pre"></span>rootPath=Environment.getExternalStorageDirectory().getParent();<span style="white-space:pre"></span>}


0 0
原创粉丝点击