如何区分Android storage USB memory和 Sdcard
1个回答
2016-08-17 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
由于现在做平板开发,必须得分出这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个路径,去得到里面的文件时,是错误的!
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个路径,去得到里面的文件时,是错误的!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询