0

I have phone (B15 CAT) with a sd card slot. When i insert a sdcard in this phone and asking for the external storage directory with :

Environment.getExternalStorageDirectory()

it always return an space on sdcard0 which is the internal memory. This memory is too small for my need. By listing /mnt i found a mount point named /sdcard2 which is the "real" scard. Unfortunately sdcard2 doesn't seems to be a standard and some other brand will use some other name...

Knowing that getExternalStorageDirectory() seems working as expected on phone with no sdcard slot , like nexus 4, how should i handle external storage to be sure to write on the sdcard (big space available) and not on internal memory ?

I have tried something like this :

File mnt = new File("/mnt");
File[] liste = mnt.listFiles();
boolean hassd2 = false;

for(File mount : liste) {
    if(folder.getName().equals("sdcard2") {
        hassd2 = true;
        break;
    }
}

String path = "";
if(hassd2) {
    path = "/sdcard2/my/folder/"
} else {
    File p = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/my/folder/");
    path = p.toString();
}

It's working but only with this specific phone and others one with no sdcard slot ...

4

1 回答 1

0

如果安装了多个“外部”存储,我也遇到了 Android 内置功能的问题。我直接从 f_stab 文件解析了挂载的目录。

链接应为您提供所需的代码。

获得挂载点后,您可以尝试计算可用空间以确定它是否足以满足您的操作。

于 2013-05-29T09:15:06.233 回答