Example usage for android.os StatFs getAvailableBlocksLong

List of usage examples for android.os StatFs getAvailableBlocksLong

Introduction

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

Prototype

public long getAvailableBlocksLong() 

Source Link

Document

The number of blocks that are free on the file system and available to applications.

Usage

From source file:Main.java

public static boolean hasEnoughSpace(float needSize) {
    if (isSDCardExist()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs sf = new StatFs(path.getPath());

        long blockSize;
        long availCount;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            blockSize = sf.getBlockSizeLong();
            availCount = sf.getAvailableBlocksLong();
        } else {/* w ww .j av  a  2  s  . co m*/
            blockSize = sf.getBlockSize();
            availCount = sf.getAvailableBlocks();
        }

        long restSize = availCount * blockSize;
        if (restSize > needSize) {
            return true;
        }
    }
    return false;
}

From source file:com.callrecorder.android.FileHelper.java

@SuppressWarnings("deprecation")
public static long getFreeSpaceAvailable(String path) {
    StatFs stat = new StatFs(path);
    long availableBlocks;
    long blockSize;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        availableBlocks = stat.getAvailableBlocksLong();
        blockSize = stat.getBlockSizeLong();
    } else {/*from   w  ww .  j  a  v  a  2s .  c o m*/
        availableBlocks = stat.getAvailableBlocks();
        blockSize = stat.getBlockSize();
    }
    return availableBlocks * blockSize;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static boolean getSDCardRemainCanWrite(Context context, long remainSize) {
    String path = getSDCardDataPath(context);
    StatFs statFS = new StatFs(path);
    long blockSize = 0L;
    if (getSDKInt() >= 18) {
        blockSize = statFS.getBlockCountLong();
    } else {/*from   w  ww .  j ava  2 s . co m*/
        blockSize = statFS.getBlockSize();
    }
    long availableBlock = 0L;
    if (getSDKInt() >= 18) {
        availableBlock = statFS.getAvailableBlocksLong();
    } else {
        availableBlock = statFS.getAvailableBlocks();
    }
    long size = blockSize * availableBlock;
    if (size > remainSize) {
        return true;
    }

    return false;
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the
 *         given File/*w  w w.  j  a va 2  s  . c  o  m*/
 */
@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

@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 {//  w  w w  .  jav a  2s.  c  o  m
            long blockSize = statFs.getBlockSizeLong();
            long blockCount = statFs.getAvailableBlocksLong();
            return blockCount * blockSize;
        }
    }
    return -1;
}

From source file:mx.klozz.xperience.tweaker.fragments.DiskInfo.java

public static long Freebytes(File f) {
    StatFs stat = new StatFs(f.getPath());
    //return (long) stat.getBlockSizeLong() * (long) stat.getAvailableBlocksLong(); <-- deprecated :) now can unse LONG in name
    return stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}

From source file:prince.app.sphotos.util.ImageCache.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//from   w w w.j a  v a2  s  .co  m
 * @return The space available in bytes
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static long getUsableSpace(File path) {
    if (Global.hasGingerbread()) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSizeLong() * (long) stats.getAvailableBlocksLong();
}

From source file:count.ly.messaging.CrashDetails.java

/**
 * Returns the current device disk space.
 */// ww  w.ja  va 2  s .  c  om
static String getDiskCurrent() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCount() * statFs.getBlockSize());
        long free = (statFs.getAvailableBlocks() * statFs.getBlockSize());
        return Long.toString((total - free) / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        long free = (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong());
        return Long.toString((total - free) / 1048576L);
    }
}

From source file:ly.count.android.sdk.CrashDetails.java

/**
 * Returns the current device disk space.
 *//*from   w  w w  . j  a  v a2  s  . co  m*/
@TargetApi(18)
static String getDiskCurrent() {
    if (android.os.Build.VERSION.SDK_INT < 18) {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = ((long) statFs.getBlockCount() * (long) statFs.getBlockSize());
        long free = ((long) statFs.getAvailableBlocks() * (long) statFs.getBlockSize());
        return Long.toString((total - free) / 1048576L);
    } else {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
        long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong());
        long free = (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong());
        return Long.toString((total - free) / 1048576L);
    }
}

From source file:com.just.agentweb.AgentWebUtils.java

public static long getAvailableStorage() {
    try {/* w w w  .  j a va 2 s.com*/
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().toString());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
        } else {
            return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
        }
    } catch (RuntimeException ex) {
        return 0;
    }
}