Example usage for android.os StatFs StatFs

List of usage examples for android.os StatFs StatFs

Introduction

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

Prototype

public StatFs(String path) 

Source Link

Document

Construct a new StatFs for looking at the stats of the filesystem at path .

Usage

From source file:Main.java

/**
 * @return The total storage in MegaBytes
 *//*from  www. j a v a2 s  . c om*/
public static Long getTotalInternalDataSize() {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long size = stat.getBlockCount() * stat.getBlockSize();
    return size / BYTES_TO_MB;
}

From source file:Main.java

public static String getSDTotalSize(Context context) {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, blockSize * totalBlocks);
}

From source file:Main.java

public static String getTotalInternalMemorySize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long totalBlocks = stat.getBlockCount();
    return Formatter.formatFileSize(context, totalBlocks * blockSize);
}

From source file:Main.java

/**
 * @return The available storage in MegaBytes
 *///ww  w.j a v a2  s.  c o  m
public static Long getAvailableInternalDataSize() {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long size = stat.getAvailableBlocks() * stat.getBlockSize();
    return size / BYTES_TO_MB;
}

From source file:Main.java

public static String getAvailableInternalMemorySize(Context context) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(context, availableBlocks * blockSize);
}

From source file:Main.java

/**
 * get the space is left over on sdcard/*from w  ww  .ja  va 2  s  .c o  m*/
 */
public static long getRealSizeOnSdcard() {
    File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}

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 {// w w w  .  j ava  2  s  . co m
        return -1;
    }
}

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("deprecation")
public static long getAvailableExternalMemorySize() {
    if (externalMemoryAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {//  w  w  w .j a  v a2s.com
        return -1;
    }
}

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