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:com.frostwire.android.util.SystemUtils.java

public static long getCurrentMountAvailableBytes() {
    StatFs stat = new StatFs(ConfigurationManager.instance().getStoragePath());
    return ((long) stat.getBlockSize() * (long) stat.getAvailableBlocks());
}

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

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

}

From source file:com.addbean.autils.tools.OtherUtils.java

public static long getAvailableSpace(File dir) {
    try {/*from   ww  w .ja v  a 2 s. c  om*/
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        return -1;
    }

}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static Boolean hasExternalStorageFreeMemory() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdAvailSize;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        sdAvailSize = (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong();
    } else {//from w  w  w.j  a va2  s  .  c om
        sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize();
    }

    return sdAvailSize >= 10 * SIZE_MB;
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static long getExternalStorageFreeMemory() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdAvailSize;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        sdAvailSize = (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong();
    } else {//from   w  w w. j  a v a2 s  .c o m
        sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize();
    }

    return Math.round(sdAvailSize / SIZE_MB);
}

From source file:net.tatans.rhea.network.view.OtherUtils.java

public static long getAvailableSpace(File dir) {
    try {/* www  . j  a  v a2  s  . c om*/
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        TatansLogUtils.e(e.getMessage(), e);
        return -1;
    }

}

From source file:cn.isif.util_plus.util.OtherUtils.java

public static long getAvailableSpace(File dir) {
    try {/*from  w  w w. ja v  a 2  s.co  m*/
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
        return -1;
    }

}

From source file:com.ddiiyy.xydz.xutils.util.OtherUtils.java

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

}

From source file:com.android.volley.misc.Utils.java

/**
 * Check how much usable space is available at a given path.
 * //from  ww w  . j  a v  a2 s. c o m
 * @param path
 *            The path to check
 * @return The space available in bytes
 */
@SuppressWarnings("deprecation")
@TargetApi(9)
public static long getUsableSpace(File path) {
    if (Utils.hasGingerbread()) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:org.proninyaroslav.libretorrent.core.utils.FileIOUtils.java

public static long getFreeSpace(String path) {
    long availableBytes = -1L;

    try {//from w  w  w. j  a v a 2  s .  c  o  m
        File file = new File(path);
        availableBytes = file.getUsableSpace();
    } catch (Exception e) {

        // this provides invalid space on some devices
        try {
            StatFs stat = new StatFs(path);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                availableBytes = stat.getAvailableBytes();
            } else {
                availableBytes = stat.getAvailableBlocks() * stat.getBlockSize();
            }
        } catch (Exception ee) {
            /* Ignore */
        }
    }

    return availableBytes;
}