Code example for StatFs

Methods: getAvailableBlocks, getBlockSize

0
        StatFs fs = null;
        long blocks = -1;
        long blockSize = -1;
        long now = System.currentTimeMillis();
 
        fs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
        blocks = fs.getAvailableBlocks() - EXTERNAL_STORAGE_BLOCK_THREADHOLD;
        blockSize = fs.getBlockSize();
        if (blocks < 0) {
            blocks = 0;
        } 
 
        if (mBlocksChangedTime == -1 || blocks != mLastBlocks) {
            mBlocksChangedTime = now;
            mLastBlocks = blocks;
        } 
 
        /* 
         * The calculation below always leaves one free block, since free space 
         * in the block we're currently writing to is not added. This last block 
         * might get nibbled when we close and flush the file, but we won't run