has Enough Space from External Storage Directory - Android Hardware

Android examples for Hardware:SD Card

Description

has Enough Space from External Storage Directory

Demo Code


//package com.java2s;

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

public class Main {

    public static boolean hasEnoughSpace(long threshold) {
        return getAvailableSpace() >= threshold;
    }//from w w w . j  av a 2 s  .  com

    @SuppressWarnings("deprecation")
    public static long getAvailableSpace() {
        String sdcard = Environment.getExternalStorageDirectory()
                .toString();
        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