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

@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 {//from   w  w w  .  ja  v a2 s . c  om
        return -1;
    }
}

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 ww.j ava2s.co m
        return "ERROR";
    }
}

From source file:Main.java

/**
 * Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android
 * devices is stored in RAM./*  w  w  w.ja  v a2 s.  com*/
 *
 * @return Number of bytes available.
 */
public static long getAvailableInternalMemorySize() {
    final File path = Environment.getDataDirectory();
    final StatFs stat = new StatFs(path.getPath());
    final long blockSize = stat.getBlockSize();
    final long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}

From source file:Main.java

/**
 * @return Free size in SDcard/*from  w w  w. ja v  a  2  s  .  c o m*/
 */
private static int sdFreeSize() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks();
    int sdFreeMegs = (int) (bytesAvailable / (1024 * 1024));
    return sdFreeMegs;
}

From source file:Main.java

public static long getUsableSpace(File path) {
    final StatFs stats = new StatFs(Environment.getExternalStorageDirectory().getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:Main.java

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

    long asize = availableBlocks * blockSize;
    LOG("getAvailaleSDCardSize asize: " + asize);
    return asize;
}

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 getFreeDiskSpace() {
    String status = Environment.getExternalStorageState();
    long freeSpace = 0;
    if (status.equals(Environment.MEDIA_MOUNTED)) {
        try {//from  w w w .j a v a2 s .  c  o m
            File path = Environment.getExternalStorageDirectory();
            StatFs stat = new StatFs(path.getPath());
            long blockSize = stat.getBlockSize();
            long availableBlocks = stat.getAvailableBlocks();
            freeSpace = availableBlocks * blockSize / 1024;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        return -1;
    }
    return (freeSpace);
}

From source file:Main.java

/**
 * Get the left size of the SDCard in Bytes.
 * //w w w .  j  a v a  2 s .co m
 * @return the left size
 */
@SuppressWarnings("deprecation")
public static long getSDCardLeftSize() {
    File sdcard = Environment.getExternalStorageDirectory();
    if (sdcard.exists()) {
        StatFs statFs = new StatFs(sdcard.getAbsolutePath());
        long blockSize = statFs.getBlockSize();
        long availableBlocks = statFs.getAvailableBlocks();

        return blockSize * availableBlocks;
    }

    return 0;
}

From source file:Main.java

public static boolean checkStorageSpace() {

    StatFs stat = new StatFs(Environment.getDataDirectory().getAbsolutePath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();

    if (blockSize * availableBlocks / 1024 / 1024 >= 128) {
        return true;
    }/*from  w  w  w . j  a va2  s .  c  om*/

    return false;
}