get Internal Storage Free Space - Android Phone

Android examples for Phone:Storage

Description

get Internal Storage Free Space

Demo Code


//package com.java2s;

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

public class Main {
    public static final int getInternalFreeSpace() {
        final String path = Environment.getDataDirectory()
                .getAbsolutePath();/*  w w w.  j av  a2  s.  c o m*/
        final int mbytes = getSpaceForFile(path);
        return mbytes;
    }

    private static final int getSpaceForFile(String path) {
        final StatFs sf = new StatFs(path);
        final int blocks = sf.getAvailableBlocks();
        final int blockSize = sf.getBlockSize();
        final int totalBytes = blocks * blockSize;
        return totalBytes;
    }
}

Related Tutorials