Zeus Zeus - 1 year ago 105
Android Question

How to Check available space on android device ? on SD card?

How do I check to see how much MB or GB is left on the android device ? I am using JAVA and android SDK 2.0.1.

Is there any system service that would expose something like this ?

Answer Source

Try that code

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;
System.out.println("Megs :"+megAvailable);

From there

UPD: getBlockCount() - return size of SD card; getAvailableBlocks() - return the number of blocks that are still accessible to normal programs (thanks Joe)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download