Example usage for android.os StatFs getAvailableBlocks

List of usage examples for android.os StatFs getAvailableBlocks

Introduction

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

Prototype

@Deprecated
public int getAvailableBlocks() 

Source Link

Usage

From source file:Main.java

/**
 * @return Available external memory//from   www.j  av  a2 s. c  o m
 */
public static int getAvailableExternalMemorySize() {
    if (isExternalStorageAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        int blockSize = stat.getBlockSize();
        int availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {
        return 0;
    }
}

From source file:Main.java

public static long getAvailableInternalRomSize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    long availBlocks = stat.getAvailableBlocks();
    return availBlocks * blockSize;
}

From source file:Main.java

public static long getFreeSpace(String dir) {
    StatFs state = null;
    try {/* w  ww  .j a  v a  2  s .c o m*/
        state = new StatFs(dir);
        long blockSize = state.getBlockSize();
        long availableCount = state.getAvailableBlocks();
        long free = availableCount * blockSize;
        if (free > 0) {
            return free;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static long getAvailableSD() {
    File path = Environment.getExternalStorageDirectory();
    StatFs statFs = new StatFs(path.getPath());
    long blockSize = statFs.getBlockSize();
    long blockCount = statFs.getBlockCount();
    long availableBlocks = statFs.getAvailableBlocks();
    return availableBlocks * blockSize;
}

From source file:Main.java

/**
 * Returns the number of bytes of external storage available.
 * @return Bytes of external storage available.
 *//*  w w w. j a  va  2s . c  om*/
static public long getAvailableExternalMemorySize() {
    if (isSDCardMounted()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {
        return -1;
    }
}

From source file:Main.java

public static long getAvailableROM() {
    File dataDirectory = Environment.getDataDirectory();
    StatFs statFs = new StatFs(dataDirectory.getPath());
    long blockSize = statFs.getBlockSize();
    long blockCount = statFs.getBlockCount();
    long availableBlocks = statFs.getAvailableBlocks();
    return availableBlocks * blockSize;
}

From source file:Main.java

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

From source file:Main.java

public static long calculateUsedDiskSpaceInBytes(String path) {
    StatFs statFs = new StatFs(path);
    long blockSizeBytes = (long) statFs.getBlockSize();
    return (blockSizeBytes * ((long) statFs.getBlockCount()))
            - (blockSizeBytes * ((long) statFs.getAvailableBlocks()));
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the
 *         given File/*from  w w  w. j  a v  a 2 s. c  o m*/
 */
public static long getAvailableBytes(File root) {
    StatFs stat = new StatFs(root.getPath());
    // put a bit of margin (in case creating the file grows the system by a
    // few blocks)
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}

From source file:com.yixia.zi.utils.UIUtils.java

public static String getAvailaleSize(Context context, String path) {
    File file = new File(path);
    if (!file.exists())
        return null;
    StatFs stat = new StatFs(path);
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(context, (availableBlocks * blockSize));
}