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

public static long getSdCardAvailableSize() {
    File sdcardDir = Environment.getExternalStorageDirectory();
    StatFs sf = null;
    try {// w w w .  j  a va2 s  . c om
        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

public static long getSdCardAvailableSize() {
    File sdcardDir = android.os.Environment.getExternalStorageDirectory();
    StatFs sf = null;
    try {//from   w  w w  .j  a  va  2s . co  m
        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

public static String showFileAvailable() {
    String result = "";
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
        long blockSize = sf.getBlockSize();
        long blockCount = sf.getBlockCount();
        long availCount = sf.getAvailableBlocks();
        return showFileSize(availCount * blockSize) + " / " + showFileSize(blockSize * blockCount);
    }//from   w ww.ja v  a  2  s . c om
    return result;
}

From source file:org.dkf.jmule.util.SystemUtils.java

public static long getAvailableStorageSize(File dir) {
    long size;/*from ww w . ja v  a 2s  .  c  o  m*/
    try {
        StatFs stat = new StatFs(dir.getAbsolutePath());
        size = ((long) stat.getAvailableBlocks()) * stat.getBlockSize();
    } catch (Exception e) {
        size = -1; // system error computing the available storage size
    }

    return size;
}

From source file:Main.java

public static long getAvailableExternalMemorySize() {
    if (isExternalMemoryAvailable() == true) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = 0;
        long availableBlocks = 0;
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();

        return availableBlocks * blockSize;
    } else {/*from  ww w  .jav  a2s  .  com*/
        return -1;
    }
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the
 *         given File//w  ww.ja va  2  s .  c om
 */
@SuppressLint("NewApi")
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)
    if (android.os.Build.VERSION.SDK_INT < 18) {
        long availableBlocks = (long) stat.getAvailableBlocks() - 4;

        return stat.getBlockSize() * availableBlocks;
    } else {
        long availableBlocks = (long) stat.getAvailableBlocksLong() - 4;
        return stat.getBlockSizeLong() * availableBlocks;
    }
}

From source file:Main.java

@SuppressWarnings("WeakerAccess")
public static long getAvailableBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }/*w w  w.j  a v  a  2 s.c om*/
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getAvailableBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getAvailableBlocks() * dirStatFs.getBlockSize();
    }
}

From source file:com.bt.download.android.util.SystemUtils.java

public static long getAvailableStorageSize(File dir) {
    long size = -1;
    try {// w w  w.j av  a  2 s .co  m
        StatFs stat = new StatFs(dir.getAbsolutePath());
        size = ((long) stat.getAvailableBlocks()) * stat.getBlockSize();
    } catch (Throwable e) {
        size = -1; // system error computing the available storage size
    }

    return size;
}

From source file:Main.java

@SuppressLint("NewApi")
public static long getSDCardAvailableSize() {
    if (isSDCardEnable()) {
        StatFs statFs = new StatFs(
                Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator);
        if (android.os.Build.VERSION.SDK_INT < 18) {
            int blockSize = statFs.getBlockSize();
            int blockCount = statFs.getAvailableBlocks();
            return blockCount * blockSize;
        } else {//www  . j a v a  2  s.c  o  m
            long blockSize = statFs.getBlockSizeLong();
            long blockCount = statFs.getAvailableBlocksLong();
            return blockCount * blockSize;
        }
    }
    return -1;
}

From source file:com.scsy150.util.OtherUtils.java

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

}