get External Storage Space via StatFs - Android Hardware

Android examples for Hardware:Storage

Description

get External Storage Space via StatFs

Demo Code


//package com.java2s;
import android.os.Environment;
import android.os.StatFs;

public class Main {
    public static long getExternalStorageSpace() {

        long space = 0;
        try {/*from w  w w  .  ja  va 2 s  .co m*/
            StatFs stat = new StatFs(Environment
                    .getExternalStorageDirectory().getAbsolutePath());
            space = (long) stat.getAvailableBlocks()
                    * (long) stat.getBlockSize();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return space;
    }
}

Related Tutorials