enough Space On Sd Card - Android Hardware

Android examples for Hardware:SD Card

Description

enough Space On Sd Card

Demo Code


//package com.java2s;
import java.io.File;

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

public class Main {

    public static boolean enoughSpaceOnSdCard(long updateSize) {
        String status = Environment.getExternalStorageState();
        if (!status.equals(Environment.MEDIA_MOUNTED))
            return false;
        return (updateSize < getRealSizeOnSdcard());
    }// w  ww .j a  va2s  . c om

    public static long getRealSizeOnSdcard() {
        File path = new File(Environment.getExternalStorageDirectory()
                .getAbsolutePath());
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    }
}

Related Tutorials