Example usage for android.os StatFs getBlockSize

List of usage examples for android.os StatFs getBlockSize

Introduction

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

Prototype

@Deprecated
public int getBlockSize() 

Source Link

Usage

From source file:com.yixia.zi.utils.UIUtils.java

public static String getAvailaleSize(Context context, String path) {
    File file = new File(path);
    if (!file.exists())
        return null;
    StatFs stat = new StatFs(path);
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(context, (availableBlocks * blockSize));
}

From source file:Main.java

public static boolean checkSDHasSpace() {
    try {//  w w  w.  j  a  va 2 s .  c  om
        StatFs statfs = new StatFs(EXTERNAL_STORAGE_DIRECTORY.getPath());
        long availaBlock = statfs.getAvailableBlocks();
        long blocSize = statfs.getBlockSize();
        long sdFreeSize = availaBlock * blocSize / 1024 / 1024;

        return sdFreeSize > SD_MIN_AVAILAALE_SIZE;
    } catch (Exception ex) {
        return false;
    }
}

From source file:Main.java

public static long getSdCardAvailableSize() {
    File sdcardDir = Environment.getExternalStorageDirectory();
    StatFs sf = null;
    try {/*from   w  w w .j  av a2  s . c  o 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 long getSdCardAvailableSize() {
    File sdcardDir = android.os.Environment.getExternalStorageDirectory();
    StatFs sf = null;
    try {//from w w  w.j a v a  2 s.  c  o  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

private static int freeSpaceOnSd() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    @SuppressWarnings("deprecation")
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB;

    return (int) sdFreeMB;
}

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 {//ww w. j  av  a  2s.c  o  m
        return -1;
    }
}

From source file:Main.java

public static long getFreeSpaceOnSd() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    //double sdFreeMB = ((double)stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB;
    return stat.getAvailableBlocks() * stat.getBlockSize();
}

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 {/*w  w w  . j  a va  2  s  .  c  o  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

@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 {/*from w  ww  . j av  a2 s .  c o m*/
            long blockSize = statFs.getBlockSizeLong();
            long blockCount = statFs.getAvailableBlocksLong();
            return blockCount * blockSize;
        }
    }
    return -1;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static long getAvailable(final File dir) {
    final StatFs statFs = new StatFs(dir.getAbsolutePath());
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return ((long) statFs.getBlockCount()) * statFs.getBlockSize();
    }/*from w  w  w  .ja  va 2 s  .  co  m*/
    return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
}