Code example for StatFs

Methods: getBlockSize, getFreeBlocks

0
 
    } 
 
    private static long getAvailableExternalStorage() 
    { 
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
        long bytesAvailable = (long) stat.getFreeBlocks() * (long) stat.getBlockSize();
        long megAvailable = bytesAvailable / 1048576;
        return megAvailable;
    } 
 
    private static long getTotalExternalStorage() 
    { 
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
        long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getBlockSize();
        long megAvailable = bytesAvailable / 1048576;
        return megAvailable;
    } 
}