Example usage for android.text.format Formatter formatFileSize

List of usage examples for android.text.format Formatter formatFileSize

Introduction

In this page you can find the example usage for android.text.format Formatter formatFileSize.

Prototype

public static String formatFileSize(@Nullable Context context, long sizeBytes) 

Source Link

Document

Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.

Usage

From source file:Main.java

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

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 getMemFreeSize(Context ctx) {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(ctx, blockSize * availableBlocks);
}

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

public static String getAvailMemory(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
    am.getMemoryInfo(mi);/*ww w. ja  v  a  2  s  . c  o m*/
    System.out.println("availMem;" + mi.availMem);
    return Formatter.formatFileSize(context, mi.availMem);
}

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

public static String getInternalMemory(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

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

From source file:Main.java

public static String getAvailableExternalMemorySize(Context context) {
    if (externalMemoryAvailable()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return Formatter.formatFileSize(context, availableBlocks * blockSize);
    } else {/*from w w w .j  a  v  a2  s. co  m*/
        return "ERROR";
    }
}

From source file:Main.java

public static String formatFileSize(Context context, long size) {
    return Formatter.formatFileSize(context, size);
}