我尝试使用此代码获取sd卡路径来存储图像:
String filepath = Environment.getExternalStorageDirectory().getAbsolutePath();
答案 0 :(得分:0)
试试这个:
String sdcardPath = Environment.getExternalStorageDirectory().getPath();
答案 1 :(得分:0)
我使用此代码成功完成了它:
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);
}