参考如下内容:
/内置sd卡路径
String sdcardPath = System.getenv("EXTERNAL_STORAGE");
//内置sd卡路径
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath();
//外置置sd卡路径
String extSdcardPath = System.getenv("SECONDARY_STORAGE");
在Enviroment类的源码中获得sd卡路径其实也是通过 System.getnv() 方法来实现的,如隐藏的方法:
/** {@hide} */
public static File getLegacyExternalStorageDirectory() {
return new File(System.getenv(ENV_EXTERNAL_STORAGE));
}
注:更详细的内容还是去看Enviroment源码。
另外要注意的是,在API 23版本中 SECONDARY_STORAGE 被移除。
手机上都有提示的。