get Available Space from External Storage Directory - Android Hardware

Android examples for Hardware:SD Card

Description

get Available Space from External Storage Directory

Demo Code


//package com.java2s;

import android.os.Environment;
import android.os.StatFs;

public class Main {

    @SuppressWarnings("deprecation")
    public static long getAvailableSpace() {
        String sdcard = Environment.getExternalStorageDirectory()
                .toString();//from   w w w  .ja v a2 s  . co m
        long space = 0;
        try {
            StatFs stat = new StatFs(sdcard);
            space = ((long) stat.getAvailableBlocks() * (long) stat
                    .getBlockSize());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return space;
    }
}

Related Tutorials