Zeus Zeus - 2 months ago 9
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

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)

Comments