Code example for StatFs

Methods: getAvailableBlocksgetBlockCountgetBlockSizegetFreeBlocks

0
     *  
     * @return xx MB 
     */ 
    protected static long readSystemAvailSize() { 
        File root = Environment.getRootDirectory();
        StatFs sf = new StatFs(root.getPath());
        long blockSize = sf.getBlockSize();
        long blockCount = sf.getBlockCount();
        long availCount = sf.getAvailableBlocks();
        long freeCount = sf.getFreeBlocks();
 
        Log.d("Swapper", "block size:" + blockSize + ",block avail:" + blockCount + ",total size:"
                + blockSize * blockCount / 1024 + "KB");
        Log.d("Swapper", "block num:" + availCount + ",avail size:" + availCount * blockSize / 1024
                + "KB" + "Free size:" + freeCount);
 
        return (availCount * blockSize) / (1024 * 1024);
    } 
 
    protected static long readSdCardAvailSize() { 
Experience pair programming with AI  Get Codota for Java