How to check SDCard free space in ANDROID?

By | April 19, 2011

This is a simple example that shows how many bytes are free in your SDCard.
Inorder to run this example, you have to create an SDCard and start the emulator with the SDCard.

Now create a fresh project and name it “” and copy the following code to it.

package pack.coderzheaven.check_space;

import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.widget.TextView;

public class FreeSpaceActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {

        StatFs stat_fs = new StatFs(Environment.getExternalStorageDirectory().getPath());
        double avail_sd_space = (double)stat_fs.getAvailableBlocks() *(double)stat_fs.getBlockSize();
        double GB_Available = (avail_sd_space / 1073741824);
        System.out.println("Available GB : " + GB_Available);

        TextView tv = (TextView)findViewById(;
        tv.setText("Your SD Card is " + GB_Available + " bytes free." );

The main.xml file

AndroidManifest file

Please leave your comments if the post was useful.

Free space in SD Card

Free Space in SD Card

Leave a Reply

Your email address will not be published. Required fields are marked *