Example usage for android.os StatFs getBlockSize

List of usage examples for android.os StatFs getBlockSize

Introduction

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

Prototype

@Deprecated
public int getBlockSize() 

Source Link

Usage

From source file:Main.java

/**
 * Returns the number of bytes of external storage available.
 * @return Bytes of external storage available.
 *//*from  w w w  . j a  v a 2s  .  c  o m*/
static public long getAvailableExternalMemorySize() {
    if (isSDCardMounted()) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } else {
        return -1;
    }
}

From source file:Main.java

public static long getAvailableStorage() {
    String storageDirectory = null;
    storageDirectory = Environment.getExternalStorageDirectory().toString();

    try {// w  w  w .  j  a va2 s.c om
        StatFs stat = new StatFs(storageDirectory);
        long avaliableSize = ((long) stat.getAvailableBlocks() * (long) stat.getBlockSize());
        return avaliableSize;
    } catch (RuntimeException ex) {
        return 0;
    }
}

From source file:Main.java

public static long getSDFreeSize() {
    StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath());
    return ((((long) sf.getAvailableBlocks()) * ((long) sf.getBlockSize())) / 1024) / 1024;
}

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);
    }//  w  w w.j a va  2  s  . com
    return result;
}

From source file:Main.java

public static long getTotalExternalMemorySize(Context context) {
    if (!isHaveSDCard()) {
        return -1;
    }// w  w  w. java 2s  . co m
    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//w ww.j  ava2  s . c om
 */
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

public static long freeSpaceOnSd() {
    StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
    long sdFreeMB = (long) stat.getAvailableBlocks() * stat.getBlockSize();
    return sdFreeMB;
}

From source file:Main.java

@SuppressLint("NewApi")
public static final long getUsableSpace(String accountName) {
    File savePath = Environment.getExternalStorageDirectory();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
        return savePath.getUsableSpace();

    } else {/* w  w  w  .j a v a 2  s.  c  o  m*/
        StatFs stats = new StatFs(savePath.getAbsolutePath());
        return stats.getAvailableBlocks() * stats.getBlockSize();
    }

}

From source file:Main.java

public static String getSavePath() {
    String savePath = null;// w  w  w  .ja v  a 2  s  .  co  m
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        savePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    } else {
        File[] files = new File("/mnt/").listFiles();
        if (files.length > 0) {
            String filePath = null;
            for (int p = 0; p < files.length; p++) {
                if (files[p].isDirectory()) {
                    if (files[p].getPath().indexOf("sdcard") >= 0) {
                        StatFs st = new StatFs(files[p].getPath());
                        int blocksize = st.getBlockSize();
                        int blockcount = st.getBlockCount();
                        if ((blocksize * blockcount) > 0) {
                            filePath = files[p].getPath();
                        }
                    }

                }
            }
            if (filePath != null) {
                savePath = filePath;
            } else {
                savePath = null;
            }
        }
    }
    return savePath;
}

From source file:Main.java

public static long FreeMemory() {
    StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
    long Free = (statFs.getAvailableBlocksLong() * statFs.getBlockSize()) / 1048576;
    return Free;/*from w w w  .  j  a  v  a 2 s .  co m*/
}