如何区分Android storage USB memory和 Sdcard

如题所述

由于现在做平板开发,必须得分出这2个存储。
USB memory和 sdcard
一般就看Enviroment类的源码。
public static File getExternalStorageDirectory() {
// Try to be smarter
// Return EXTERNAL_STORAGE_DIRECTORY_SD if SD card is ready
// Return EXTERNAL_STORAGE_DIRECTORY_UDISK if SD card is absent but udisk is ready
// Return EXTERNAL_STORAGE_DIRECTORY_SD if both sd card and udisk are not ready
String propSD = SystemProperties.get("EXTERNAL_STORAGE_STATE_SD", MEDIA_REMOVED);
String propUDISK = SystemProperties.get("EXTERNAL_STORAGE_STATE_UDISK", MEDIA_REMOVED);
String propEXTSD = SystemProperties.get("EXTERNAL_STORAGE_STATE_EXTSD", MEDIA_REMOVED);
if (propSD.equals(MEDIA_MOUNTED) || propSD.equals(MEDIA_MOUNTED_READ_ONLY)) {
return EXTERNAL_STORAGE_DIRECTORY_SD;
} else if (propUDISK.equals(MEDIA_MOUNTED) || propUDISK.equals(MEDIA_MOUNTED_READ_ONLY)) {
return EXTERNAL_STORAGE_DIRECTORY_UDISK;
} else if (propEXTSD.equals(MEDIA_MOUNTED) || propEXTSD.equals(MEDIA_MOUNTED_READ_ONLY)) {
return EXTERNAL_STORAGE_DIRECTORY_EXTSD;} else {return EXTERNAL_STORAGE_DIRECTORY_SD;}}然后Environment.getExternalStorageDirectory().getAbsolutePath()
看返回的是"/sdcard"还是"/udisk"既可。
如果你直接指定这2个路径,去得到里面的文件时,是错误的!
温馨提示:答案为网友推荐,仅供参考
相似回答