Code example for StatFs

Methods: getAvailableBlocks, getBlockSize

0
     * 
     * @return Number of bytes available. 
     */ 
    public static long getAvailableInternalMemorySize() { 
        final File path = Environment.getDataDirectory();
        final StatFs stat = new StatFs(path.getPath());
        final long blockSize = stat.getBlockSize();
        final long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } 
 
    /** 
     * Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android 
     * devices is stored in RAM. 
     * 
     * @return Total number of bytes. 
     */ 
    public static long getTotalInternalMemorySize() { 
        final File path = Environment.getDataDirectory();
        final StatFs stat = new StatFs(path.getPath());
        final long blockSize = stat.getBlockSize();