如何区分Android storage USB memory和 Sdcard
答案:2 悬赏:70 手机版
解决时间 2021-01-24 09:49
- 提问者网友:你挡着我发光了
- 2021-01-24 03:18
如何区分Android storage USB memory和 Sdcard
最佳答案
- 五星知识达人网友:duile
- 2021-01-24 03:57
由于现在做平板开发,必须得分出这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个路径,去得到里面的文件时,是错误的!
全部回答
- 1楼网友:杯酒困英雄
- 2021-01-24 04:59
我。。知。。道
加。。我。。私。。聊
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯