How can I check how much free space an SD card mounted on an Android device has?

To get the external SD card’s available “free” space to show a number which agrees with the Menu->Settings->SD card and phone storage’s number, use the following code:

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
double sdAvailSize = (double)stat.getAvailableBlocks()
                   * (double)stat.getBlockSize();
//One binary gigabyte equals 1,073,741,824 bytes.
double gigaAvailable = sdAvailSize / 1073741824;

Relevant documentation: http://developer.android.com/reference/android/os/StatFs.html

Leave a Comment