Example usage for android.os StatFs getAvailableBlocks

List of usage examples for android.os StatFs getAvailableBlocks

Introduction

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

Prototype

@Deprecated
public int getAvailableBlocks() 

Source Link

Usage

From source file:Main.java

public static long getInternalMemorySize() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();

    return availableBlocks * blockSize;
}

From source file:Main.java

/**
 * get the space is left over on phone self
 *//*from   w  ww.j av a  2 s.  c  o  m*/
public static long getRealSizeOnPhone() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return blockSize * availableBlocks;
}

From source file:Main.java

/**
 * get the space is left over on sdcard//from  w  w  w.  j ava 2  s  .  co 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

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

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check// w  ww. ja v a 2  s .  co m
 *
 * @return The space available in bytes
 */
public static long getUsableSpace(File path) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:Main.java

public static int freeSpaceOnSD() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()) / 1024 * 1024;
    return (int) sdFreeMB;
}

From source file:Main.java

/**
 * Check how much usable space is available at a given path.
 *
 * @param path The path to check//  w w w .  j  a va  2s .  com
 * @return The space available in bytes
 */
@SuppressLint("NewApi")
public static long getUsableSpace(File path) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        return path.getUsableSpace();
    }
    final StatFs stats = new StatFs(path.getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:Main.java

public static long getAvailableSize(String path) {
    try {//from   w w  w.  ja v a2 s.  c o m
        File base = new File(path);
        StatFs stat = new StatFs(base.getPath());
        long nAvailableCount = stat.getBlockSize() * ((long) stat.getAvailableBlocks());
        return nAvailableCount;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

/**
 * get the space is left over on phone self
 *///from  w ww  . ja  v  a2 s.  c o  m
public static long getRealSizeOnPhone() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    long realSize = blockSize * availableBlocks;
    return realSize;
}

From source file:Main.java

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