List of usage examples for android.os StatFs StatFs
public StatFs(String path)
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 long getAvailableExternalMemorySize() throws IllegalArgumentException { 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 ww w . j a va 2 s. c o m return -1; } }
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 {/*from w w w .j av a 2s . c om*/ 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 {/* w w w . j a va 2 s . c o m*/ return "ERROR"; } }
From source file:Main.java
/** * Gets the free disk space at the specified location. * * @param dir/*from w w w .jav a 2 s. c o m*/ * the directory linking to the filesystem to query * @return the free disk space at {@code dir} in bytes */ private static long getFreeDiskSpace(File dir) { StatFs statFs = new StatFs(dir.getAbsolutePath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { //noinspection deprecation return statFs.getBlockCount() * statFs.getBlockSize(); } }
From source file:Main.java
static long calculateApiDiskCacheSize(File dir) { long size = MIN_DISK_API_CACHE_SIZE; try {// w ww . j a va 2s .co m StatFs statFs = new StatFs(dir.getAbsolutePath()); long available; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { available = ((long) statFs.getBlockCount()) * statFs.getBlockSize(); } // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE); }
From source file:Main.java
public static boolean checkSDHasSpace() { try {/*from www . ja va2 s .c om*/ StatFs statfs = new StatFs(EXTERNAL_STORAGE_DIRECTORY.getPath()); long availaBlock = statfs.getAvailableBlocks(); long blocSize = statfs.getBlockSize(); long sdFreeSize = availaBlock * blocSize / 1024 / 1024; return sdFreeSize > SD_MIN_AVAILAALE_SIZE; } catch (Exception ex) { return false; } }
From source file:Main.java
public static long getFreeSpaceOnSd() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); //double sdFreeMB = ((double)stat.getAvailableBlocks() * (double) stat.getBlockSize()) / MB; return stat.getAvailableBlocks() * stat.getBlockSize(); }
From source file:Main.java
protected static StatFs createStatFs(String path) { return new StatFs(path); }
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); }/*from w w w. java2s. c om*/ return result; }