2

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

dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
reza
  • 1,329
  • 2
  • 22
  • 37

1 Answers1

3

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.

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • My Acer Iconia (Android 3.2) treats it differently again, it has the internal storage as /sdcard/ and /mnt/sdcard/ but the real SD card only appears in /mnt/external_sd – jsnfwlr Oct 17 '11 at 06:50
  • @phalacee: thank for the info. Yeah, this is one area where SDK is moot. – Peter Knego Oct 17 '11 at 08:27
  • so what's the right strategy in terms of writing to the SD card? – reza Oct 17 '11 at 22:48
  • i rooted the phone and checked the filesystem, seems it shows up as /mnt/storage/sdcard -- that's super annoying. Guess the solution would be device specific... – reza Oct 17 '11 at 23:32