【发布时间】:2015-03-08 23:06:59
【问题描述】:
我尝试使用以下代码获取存储图像的 sd 卡路径:
字符串文件路径 = Environment.getExternalStorageDirectory().getAbsolutePath();
但它不适用于所有设备和所有版本的 android。
【问题讨论】:
标签: android
我尝试使用以下代码获取存储图像的 sd 卡路径:
字符串文件路径 = Environment.getExternalStorageDirectory().getAbsolutePath();
【问题讨论】:
标签: android
试试这个:
String sdcardPath = Environment.getExternalStorageDirectory().getPath();
【讨论】:
我使用这段代码成功地做到了:
public File getSDPath() {
String filepath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
if (android.os.Build.DEVICE.contains("samsung")
|| android.os.Build.MANUFACTURER.contains("samsung")) {
File f = new File(Environment.getExternalStorageDirectory()
.getParent() + "/extSdCard");
if (f.exists() && f.isDirectory()) {
try {
File file = new File(f, "test");
FileOutputStream fos = new FileOutputStream(file);
filepath = Environment.getExternalStorageDirectory()
.getParent() + "/extSdCard";
} catch (FileNotFoundException e) {
}
} else {
f = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/external_sd");
if (f.exists() && f.isDirectory()) {
try {
File file = new File(f, "test");
FileOutputStream fos = new FileOutputStream(file);
filepath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/external_sd";
} catch (FileNotFoundException e) {
}
}
}
}
return new File(filepath);
}
【讨论】:
/mnt/extsd/