今天做项目遇到一点,需要获取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>}