Android check for SD Card mounted always returns true

2.9k views Asked by At

I'm not sure what the source of the problem is - older android version with bug or if I'm doing something wrong, but my problem is that no matter what I do, android reports the SD card as mounted. Even if it's not physically in the tablet (archos 7o)..

public boolean saveToDisk(String filename, String header) {
    /* first check to see if the SD card is mounted */
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        //throw some exception so we can display an error message 
        // XXX
        return false;
    }
    try {
        File root = Environment.getExternalStorageDirectory();
        File dir = new File(root.getAbsolutePath() + "/bioz");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File file = new File(dir, filename);
        ....

The first test is always true, getExternalStorageDirectory() responds with /mnt/storage and the test to see if /mnt/storage/bioz exists indicates that the directory does exist.

Any idea what's going on? Am I doing something wrong, is the API broken, or something else?

Thanks, Reza

1

There are 1 answers

4
Peter Knego On BEST ANSWER

External storage is not the same as SD card, at least not on all devices. Devices that have internal flash memory (for example my Nexus S does) threat this as " external storage".

Now, devices that have both internal flash and SD card, threat internal flash as external memory and SD card is then added as directory under this external memory.

From programmers view it's a pain, but not much we can do about it.