List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:Main.java
public static long getAvailableExternalMemorySize() { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
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 {/*from w ww . ja 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 int getFreeMemory(String path) { StatFs statFs = new StatFs(path); int free = (statFs.getAvailableBlocks() * statFs.getBlockSize()); return Math.abs(free); }
From source file:Main.java
/** * @return Total external memory/*from ww w . jav a2 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 long getTotalExternalMemorySize() { if (!isHaveSDCard()) { return -1; }// w w w . j a va 2 s . c o m File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long blockCount = stat.getBlockCount(); return blockSize * blockCount; }
From source file:Main.java
/** * Returns the number of bytes of external storage available. * @return Bytes of external storage available. *//*from w w w. java 2 s . 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
/** * Returns the total number of bytes of external storage. * @return Bytes of external storage in total, or -1 if no SD card mounted. *//*from w w w . j a va 2s .c o m*/ static public long getTotalExternalMemorySize() { if (isSDCardMounted()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } else { return -1; } }
From source file:com.phonegap.DirectoryManager.java
/** * Get the free disk space on the SD card * //from ww w . j av a 2 s. c o m * @return Size in KB or -1 if not available */ protected static long getFreeDiskSpace() { String status = Environment.getExternalStorageState(); long freeSpace = 0; // If SD card exists if (status.equals(Environment.MEDIA_MOUNTED)) { try { 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(); } } // If no SD card, then return -1 else { return -1; } return (freeSpace); }
From source file:Main.java
public static long getAvailableExternalMemorySize() { if (isExternalMemoryAvailable() == true) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = 0; long availableBlocks = 0; blockSize = stat.getBlockSize(); availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } else {/*from ww w.j a v a2s .c om*/ return -1; } }
From source file:Main.java
/** * Get the number of tiles that can be stored on the file system. * * @param directory where the cache will reside * @param fileSize average size of tile to be cached * @return number of tiles that can be stored without running out of space *///www. java 2 s . c o m @SuppressWarnings("deprecation") @TargetApi(18) public static long getAvailableCacheSlots(String directory, int fileSize) { StatFs statfs = new StatFs(directory); if (android.os.Build.VERSION.SDK_INT >= 18) { return statfs.getAvailableBytes() / fileSize; } // problem is overflow with devices with large storage, so order is important here // additionally avoid division by zero in devices with a large block size int blocksPerFile = Math.max(fileSize / statfs.getBlockSize(), 1); return statfs.getAvailableBlocks() / blocksPerFile; }