枚举安装在Android手机上的SD卡

时间:2012-11-28 15:10:36

标签: android sd-card mount

如何从Java或本机代码中枚举安装在Android手机上的所有SD卡?

1 个答案:

答案 0 :(得分:0)

这不仅会列出已安装的sdcards,还会列出Android设备上所有已安装的文件系统。

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cat /proc/mounts");
BufferedReader stdInput = new BufferedReader(new 
     InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new 
     InputStreamReader(proc.getErrorStream()));
// read the output from the command
while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
}