Example usage for android.os StatFs StatFs

List of usage examples for android.os StatFs StatFs

Introduction

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

Prototype

public StatFs(String path) 

Source Link

Document

Construct a new StatFs for looking at the stats of the filesystem at path .

Usage

From source file:Main.java

public static long getAvailableSpace(File dir) {
    try {/*from  ww  w.j a v a2  s.c  o  m*/
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        Log.e("getAvailableSpace", e.getMessage(), e);
        return -1;
    }
}

From source file:Main.java

public static long getFreeSpace(String dir) {
    StatFs state = null;//from  w w w.j av a2  s  .  com
    try {
        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

public static long getSDSize() {
    String str = Environment.getExternalStorageDirectory().getPath();
    StatFs localStatFs = new StatFs(str);
    long blockSize = localStatFs.getBlockSize();
    return localStatFs.getAvailableBlocks() * blockSize;
}

From source file:Main.java

public static int freeSpaceOnSd() {
    StatFs stat = new StatFs(getSDPath());
    double sdFree = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize());
    return (int) sdFree;
}

From source file:Main.java

public static long computeFreeSpace() {
    File dataDir = Environment.getDataDirectory();
    StatFs stat = new StatFs(dataDir.getPath());
    return stat.getAvailableBlocks() * stat.getBlockSize();
}

From source file:Main.java

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

From source file:Main.java

public static long getSDSize() {
    final String str = Environment.getExternalStorageDirectory().getPath();
    final StatFs localStatFs = new StatFs(str);
    final long blockSize = localStatFs.getBlockSize();
    return localStatFs.getAvailableBlocks() * blockSize;
}

From source file:Main.java

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

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 getInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();

    return availableBlocks * blockSize;
}