在我的手機中,我有兩個存儲區,其中一個是SD卡,另一個是extsdcard
。如何在Android上獲取多個存儲文件路徑?
我可以得到由SD卡路徑:
Environment.getExternalStorageDirectory()
.toString()
如何得到extsdcard文件路徑?
在我的手機中,我有兩個存儲區,其中一個是SD卡,另一個是extsdcard
。如何在Android上獲取多個存儲文件路徑?
我可以得到由SD卡路徑:
Environment.getExternalStorageDirectory()
.toString()
如何得到extsdcard文件路徑?
使用該工具來獲取其他外部SD卡:
File storageDir= new File("/mnt/external_sd/")
OR
File storageDir= new File("/mnt/extSdCard/")
欲瞭解更多詳情,請參見http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-td5710218.html#a5710250和this
所以,像這樣用一個函數來獲取列表所有分機卡...
public static HashSet<String> getExternalMounts() {
final HashSet<String> out = new HashSet<String>();
String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
String s = "";
try {
final Process process = new ProcessBuilder().command("mount")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
s = s + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
// parse output
final String[] lines = s.split("\n");
for (String line : lines) {
if (!line.toLowerCase(Locale.US).contains("asec")) {
if (line.matches(reg)) {
String[] parts = line.split(" ");
for (String part : parts) {
if (part.startsWith("/"))
if (!part.toLowerCase(Locale.US).contains("vold"))
out.add(part);
}
}
}
}
return out;
}
您正在使用哪種設備? – Raghunandan
android手機版本4.0.4,不是國際品牌。 – RealDream