0

Possible Duplicate:
Android SD card free space

On some devices external sdcards are mounted in /mnt/sdcard/tflash . Now I need to find out how much free space is on the external sdcard .

I can't test it, so I am not sure if the following returns the size of /mnt/sdcard/tflash insteed of /mnt/sdcard

        StatFs stat = new StatFs("/mnt/sdcard/tflash");
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;

Any hints how to find the free space of /mnt/sdcard/tflash or /mnt/sdcard/external_sd

Community
  • 1
  • 1
mcfly soft
  • 11,289
  • 26
  • 98
  • 202

2 Answers2

3

Unfortunately, Android really doesn't have the concept of a truly "external sd card", in fact, their external storage is commonly referred to something people usually consider internal memory (like the 8gb that comes imbedded with a device!)

Environment.getExternalStorageState() returns path to internal SD mount point like "/mnt/sdcard"

Environment.getExternalStorageDirectory() is whatever the device manufacturer considered to be "external storage". Sometimes this is truly removable storage, sometimes it isn't!!

I hate to burst the bubble, but there may be no way but to check for paths like /mnt/sdcard/external_sd manually, and check if they exist, then check size. That is what I ended up doing for on of my apps :(

programmer33
  • 642
  • 8
  • 19
0

Try

StatFs st = new StatFs(Environment.getExternalStorageDirectory().getPath());

long sdcardSize = (long) st.getBlockSize() * (long) st.getBlockCount();
maninder singh
  • 1,286
  • 13
  • 16
  • This gives me the size of /mnt/sdcard/ , but I need the size of a mounted external sd-card on /mnt/sdcard/external_sd – mcfly soft Oct 10 '12 at 14:12