1、获取外置SDCard
public static String getExSDCardPath() {
String sdcard_path = null;
String sd_default = Environment.getExternalStorageDirectory()
.getAbsolutePath();
try {
Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("mount");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
String line;
String mount = new String();
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
if (line.contains("secure"))
continue;
if (line.contains("asec"))
continue;
if ((line.toLowerCase().contains("fat") && line.toLowerCase().contains("/storage/sd")) ||
(line.toLowerCase().contains("fat") && line.toLowerCase().contains("/storage/ext"))) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
if (sd_default.trim().equals(columns[1].trim())) {
continue;
}
sdcard_path = columns[1];
}
} else if ((line.toLowerCase().contains("fuse") && line.toLowerCase().contains("/storage/sd"))
|| (line.toLowerCase().contains("fuse") && line.toLowerCase().contains("/storage/ext"))) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
if (sd_default.trim().equals(columns[1].trim())) {
continue;
}
sdcard_path = columns[1];
}
}else if ((line.toLowerCase().contains("mnt") && line.toLowerCase().contains("/storage/sd"))
|| (line.toLowerCase().contains("mnt") && line.toLowerCase().contains("/storage/ext"))) {
String columns[] = line.split(" ");
if (columns != null && columns.length > 1) {
if (sd_default.trim().equals(columns[1].trim())) {
continue;
}
sdcard_path = columns[1];
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
return sd_default;
} catch (IOException e) {
e.printStackTrace();
return sd_default;
}
if(sdcard_path != null){
sdcard_path += "/Android/data/+"+CourserApplication.getContext().getPackageName()+"/files";
return sdcard_path;
}else{
return sd_default;
}
}