List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:Main.java
public static long getUsableSpace(File path) { final StatFs stats = new StatFs(path.getPath()); return stats.getBlockCount() * stats.getAvailableBlocks(); }
From source file:Main.java
/** * @return Total internal memory//from w ww .ja v a 2 s . co m */ public static int getTotalInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); int blockSize = stat.getBlockSize(); int totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; }
From source file:Main.java
/** * @return Available internal memory/*from ww w . ja va2 s.c o m*/ */ public static int getAvailableInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); int blockSize = stat.getBlockSize(); int availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:Main.java
/** * @return the number of bytes available on the filesystem rooted at the * given File//from w ww . j a va 2 s. com */ @SuppressLint("NewApi") public static long getAvailableBytes(File root) { StatFs stat = new StatFs(root.getPath()); // put a bit of margin (in case creating the file grows the system by a // few blocks) if (android.os.Build.VERSION.SDK_INT < 18) { long availableBlocks = (long) stat.getAvailableBlocks() - 4; return stat.getBlockSize() * availableBlocks; } else { long availableBlocks = (long) stat.getAvailableBlocksLong() - 4; return stat.getBlockSizeLong() * availableBlocks; } }
From source file:Main.java
/** * the number of bytes on the filesystem rooted at the given File * /*from ww w . j ava 2s.c o m*/ * @param root * root file dir. * @return the number of bytes available on the filesystem rooted at the * given File */ public static long getTotaltes(File root) { StatFs stat = new StatFs(root.getPath()); // put a bit of margin (in case creating the file grows the system by a // few blocks) long availableBlocks = (long) stat.getBlockCount() - 4; // SUPPRESS // CHECKSTYLE // // CHECKSTYLE return stat.getBlockSize() * availableBlocks; }
From source file:Main.java
/** * @return Available external memory/*from ww w . j ava2 s.co m*/ */ public static int getAvailableExternalMemorySize() { if (isExternalStorageAvailable()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); int blockSize = stat.getBlockSize(); int availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } else { return 0; } }
From source file:Main.java
@Deprecated public static boolean checkRomSpaceEnough(long limitSize) { long allSize; long availableSize = 0; try {//from ww w. j a v a 2 s . c o m File data = Environment.getDataDirectory(); StatFs sf = new StatFs(data.getPath()); availableSize = (long) sf.getAvailableBlocks() * (long) sf.getBlockSize(); allSize = (long) sf.getBlockCount() * (long) sf.getBlockSize(); } catch (Exception e) { allSize = 0; } if (allSize != 0 && availableSize > limitSize) { return true; } return false; }
From source file:Main.java
/** * Check how much usable space is available at a given path. * * @param path The path to check/*w ww. j a va2 s .c om*/ * * @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
/** * Check if has enough space for record//from w ww .j a va 2 s . c o m * * @param recordingSdcard The recording sdcard path * * @return true if has enough space for record */ public static boolean hasEnoughSpace(String recordingSdcard) { boolean ret = false; try { StatFs fs = new StatFs(recordingSdcard); long blocks = fs.getAvailableBlocks(); long blockSize = fs.getBlockSize(); long spaceLeft = blocks * blockSize; ret = spaceLeft > LOW_SPACE_THRESHOLD ? true : false; } catch (IllegalArgumentException e) { Log.e(TAG, "hasEnoughSpace, sdcard may be unmounted:" + recordingSdcard); } return ret; }
From source file:Main.java
/** * Check how much usable space is available at a given path. * * @param path The path to check//from w w w . j a v a 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(); }