Example usage for android.os StatFs getBlockCount

List of usage examples for android.os StatFs getBlockCount

Introduction

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

Prototype

@Deprecated
public int getBlockCount() 

Source Link

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static long getTotalExternalMemorySize() {
    if (externalMemoryAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;
    } else {/*from   ww w.  j a v  a 2  s  . c  o m*/
        return -1;
    }
}

From source file:Main.java

public static String getTotalExternalMemorySize(Context context) {
    if (externalMemoryAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        return Formatter.formatFileSize(context, totalBlocks * blockSize);
    } else {//from  w  w w  .  jav  a 2s. c  o m
        return "ERROR";
    }
}

From source file:Main.java

/**
 * Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android
 * devices is stored in RAM.//from  w w  w .jav a  2s .  com
 *
 * @return Total number of bytes.
 */
public static long getTotalInternalMemorySize() {
    final File path = Environment.getDataDirectory();
    final StatFs stat = new StatFs(path.getPath());
    final long blockSize = stat.getBlockSize();
    final long totalBlocks = stat.getBlockCount();
    return totalBlocks * 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 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  ww w .j  av a2s . c  o  m
    return result;
}

From source file:Main.java

/**
 * Returns the total number of bytes of external storage.
 * @return Bytes of external storage in total, or -1 if no SD card mounted.
 *//*from  w  ww .jav a2  s . co  m*/
static public long getTotalExternalMemorySize() {
    if (isSDCardMounted()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;
    } else {
        return -1;
    }
}

From source file:Main.java

public static long getTotalExternalMemorySize(Context context) {
    if (!isHaveSDCard()) {
        return -1;
    }/*  ww w  .  ja  v  a2  s .c  om*/
    StatFs sFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
    long blockSize = sFs.getBlockSize();
    long totalBlocks = sFs.getBlockCount();
    return blockSize * totalBlocks;
}

From source file:Main.java

/**
 * @return Total external memory//from  w  ww  .j  a va 2 s .c  o m
 */
public static int getTotalExternalMemorySize() {
    if (isExternalStorageAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        int blockSize = stat.getBlockSize();
        int totalBlocks = stat.getBlockCount();
        return totalBlocks * blockSize;
    } else {
        return 0;
    }
}

From source file:Main.java

@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
    long allSize;
    long availableSize = 0;
    try {// w  w w.j  a  va  2  s  .  c  o  m
        File data = Environment.getDataDirectory();
        StatFs sf = new StatFs(data.getPath());
        availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize();
        allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize();
    } catch (Exception e) {
        allSize = 0;
    }

    if (allSize != 0 && availableSize > limitSize) {
        return true;
    }
    return false;
}

From source file:Main.java

public static long getTotalExternalMemorySize() {
    if (isExternalMemoryAvailable() == true) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = 0;
        long totalBlocks = 0;
        blockSize = stat.getBlockSize();
        totalBlocks = stat.getBlockCount();

        return totalBlocks * blockSize;
    } else {//from  w w w .  ja  v a 2  s.  com
        return -1;
    }
}