enough Space On Phone - Android Hardware

Android examples for Hardware:Storage

Description

enough Space On Phone

Demo Code


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

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

public class Main {

    public static boolean enoughSpaceOnPhone(long updateSize) {
        return getRealSizeOnPhone() > updateSize;
    }//from   w ww. j  a  v  a2s. c  o m

    public static long getRealSizeOnPhone() {
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        long realSize = blockSize * availableBlocks;
        return realSize;
    }
}

Related Tutorials