Example usage for android.os StatFs getBlockSize

List of usage examples for android.os StatFs getBlockSize

Introduction

In this page you can find the example usage for android.os StatFs getBlockSize.

Prototype

@Deprecated
public int getBlockSize() 

Source Link

Usage

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the given File
 *///from ww w  . j  a  v  a 2 s . c  o m
public static long getAvailableBytes(File root) {
    StatFs stat = new StatFs(root.getPath());
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}

From source file:Main.java

@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
    long allSize;
    long availableSize = 0;
    try {/*from w ww  . ja v a 2s  .  c o m*/
        File data = Environment.getDataDirectory();
        StatFs sf = new StatFs(data.getPath());
        availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
        allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
    } catch (Exception e) {
        allSize = 0;
    }

    if (allSize != 0 && availableSize > limitSize) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * **********************************************************************************************
 * Returns size in MegaBytes.//w w  w  .  ja v  a  2 s.co m
 *
 * @author Dan
 * <p/>
 * If you need calculate external memory, change this: StatFs statFs
 * = new StatFs(Environment.getRootDirectory().getAbsolutePath());
 * to this: StatFs statFs = new
 * StatFs(Environment.getExternalStorageDirectory
 * ().getAbsolutePath());
 * ************************************************************************************************
 */
public static long TotalMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
    long Total = (statFs.getBlockCountLong() * statFs.getBlockSize()) / 1048576;
    return Total;
}

From source file:Main.java

public static int freeSpaceOnSd() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB;
    return (int) sdFreeMB;
}

From source file:Main.java

public static int freeSpaceOnSd() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB;

    return (int) sdFreeMB;
}

From source file:Main.java

public static long getTotalExternalMemorySize() {
    if (isExternalMemoryAvailable() == true) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = 0;
        long totalBlocks = 0;
        blockSize = stat.getBlockSize();
        totalBlocks = stat.getBlockCount();

        return totalBlocks * blockSize;
    } else {/*from ww  w.  ja va2 s  . co  m*/
        return -1;
    }
}

From source file:Main.java

public static long getExternalStorageSpace() {

    long space = 0;
    try {/*from  w  ww.  ja  v a  2s .  c o m*/
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
        space = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return space;
}

From source file:Main.java

/**
 * Check if has enough space for record//from w  ww  .j a  va 2  s  .  c  o  m
 *
 * @param recordingSdcard The recording sdcard path
 *
 * @return true if has enough space for record
 */
public static boolean hasEnoughSpace(String recordingSdcard) {
    boolean ret = false;
    try {
        StatFs fs = new StatFs(recordingSdcard);
        long blocks = fs.getAvailableBlocks();
        long blockSize = fs.getBlockSize();
        long spaceLeft = blocks * blockSize;
        ret = spaceLeft > LOW_SPACE_THRESHOLD ? true : false;
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "hasEnoughSpace, sdcard may be unmounted:" + recordingSdcard);
    }
    return ret;
}

From source file:Main.java

public static long getSDCardAvailableAtKB() {
    StatFs sfs = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long availableCount = sfs.getAvailableBlocks();
    long blockSizea = sfs.getBlockSize();
    return (availableCount * blockSizea) / 1024;
}

From source file:Main.java

public static int freeSpaceOnSD() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024;
    return (int) sdFreeMB;
}