1

在我的手机中,我有两个存储器,一个是 SD 卡,另一个是extsdcard.

我可以通过以下方式获取 sdcard 路径:

Environment.getExternalStorageDirectory()
.toString()

如何获取 extsdcard 文件路径?

4

1 回答 1

2

使用它来获取另一个外部 sdcard:

 File storageDir=   new File("/mnt/external_sd/")

或者

 File storageDir=   new File("/mnt/extSdCard/")

有关更多详细信息,请参阅http://mono-for-android.1047100.n5.nabble.com/detect-SD-Card-path-td5710218.html#a5710250这个

所以像这样使用一个函数来获取所有扩展卡的列表......

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;
}
于 2013-05-21T08:41:11.100 回答