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 getSDCardAvailableCount() {
    StatFs statfs = new StatFs(SDCARD_PATH);
    return ((long) statfs.getAvailableBlocks()) * statfs.getBlockSize();
}

From source file:Main.java

public static float getSDCardFreeSize() {
    try {/*from   w w  w. j ava 2  s  . co m*/
        String path = Environment.getExternalStorageDirectory().getPath();
        StatFs fs = new StatFs(path);
        return calculateSizeInMB(fs);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return 0;
}

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 boolean isDirectoryValid(String path) {
    File file = new File(path);
    if (!file.canWrite()) {
        return false;
    }/*from   w  ww  .  j  a v a 2s.com*/
    StatFs sf = new StatFs(file.getPath());
    long availCount = sf.getAvailableBlocks();
    if (availCount > 0) {
        return true;
    }
    return false;
}

From source file:Main.java

public static long getSdCardAvailableSize() {
    File sdcardDir = android.os.Environment.getExternalStorageDirectory();
    StatFs sf = null;//from w ww  . ja  v  a 2s  .  c  om
    try {
        sf = new StatFs(sdcardDir.getPath());
    } catch (Exception e) {
        return 0;
    }
    long blockSize = sf.getBlockSize();
    long availCount = sf.getAvailableBlocks();
    return availCount * blockSize;
}

From source file:Main.java

@SuppressWarnings("deprecation")
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 getAvailableStorage() {
    try {/*from   ww w  . java  2  s.c o  m*/
        String storageDirectory = Environment.getExternalStorageDirectory().toString();
        StatFs stat = new StatFs(storageDirectory);
        return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    } catch (Exception e) {
        // if we can't stat the filesystem then we don't know how many
        // pictures are remaining. it might be zero but just leave it
        // blank since we really don't know.
        return 0;
    }
}

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 String getStorageSize(Context context) {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    return Formatter.formatFileSize(context, ((long) stat.getBlockSize()) * ((long) stat.getBlockCount()));
}

From source file:Main.java

public static long getSdCardAvailableSize() {
    File sdcardDir = Environment.getExternalStorageDirectory();
    StatFs sf = null;//from  ww w.  jav  a2  s.c  o m
    try {
        sf = new StatFs(sdcardDir.getPath());
    } catch (Exception e) {
        return 0;
    }
    long blockSize = sf.getBlockSize();
    long availCount = sf.getAvailableBlocks();
    return availCount * blockSize;
}