List of usage examples for android.os StatFs getAvailableBlocks
@Deprecated public int getAvailableBlocks()
From source file:com.phonegap.DirectoryManager.java
/** * Get the free disk space on the SD card * // w w w . j a v a 2 s .c om * @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:com.sqkj.engine.image.ImageCache.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 .c o m*/ * @return The space available in bytes */ public static long getUsableSpace(File path) { if (SdkUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.lxh.util.image.OtherUtils.java
/** * ??// ww w . j a v a2s . c om * @param dir {@link java.io.File} * @return ????byte-1 */ public static long getAvailableSpace(File dir) { try { final StatFs stats = new StatFs(dir.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); } catch (Throwable e) { return -1; } }
From source file:Main.java
public static boolean hasEnoughSpace(float needSize) { if (isSDCardExist()) { File path = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(path.getPath()); long blockSize; long availCount; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = sf.getBlockSizeLong(); availCount = sf.getAvailableBlocksLong(); } else {// w w w . j a v a 2 s . com blockSize = sf.getBlockSize(); availCount = sf.getAvailableBlocks(); } long restSize = availCount * blockSize; if (restSize > needSize) { return true; } } return false; }
From source file:Main.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") public static boolean getSDCardRemainCanWrite(Context context, long remainSize) { String path = getSDCardDataPath(context); StatFs statFS = new StatFs(path); long blockSize = 0L; if (getSDKInt() >= 18) { blockSize = statFS.getBlockCountLong(); } else {// w w w. jav a2 s. c om blockSize = statFS.getBlockSize(); } long availableBlock = 0L; if (getSDKInt() >= 18) { availableBlock = statFS.getAvailableBlocksLong(); } else { availableBlock = statFS.getAvailableBlocks(); } long size = blockSize * availableBlock; if (size > remainSize) { return true; } return false; }
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 *//* w w w.j av a 2s. com*/ @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; }
From source file:com.callrecorder.android.FileHelper.java
@SuppressWarnings("deprecation") public static long getFreeSpaceAvailable(String path) { StatFs stat = new StatFs(path); long availableBlocks; long blockSize; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { availableBlocks = stat.getAvailableBlocksLong(); blockSize = stat.getBlockSizeLong(); } else {/*from w ww .java 2 s .c om*/ availableBlocks = stat.getAvailableBlocks(); blockSize = stat.getBlockSize(); } return availableBlocks * blockSize; }
From source file:com.secbro.qark.filebrowser.FileBrowserFragment.java
public static long getFreeSpace(String path) { StatFs stat = new StatFs(path); long availSize = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); return availSize; }
From source file:id.wibisana.priadimulia.imagecaching.cache.ImageCache.java
@SuppressWarnings("deprecation") @TargetApi(9)//ww w .j av a2 s .co m 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:eu.geopaparazzi.library.util.Utilities.java
/** * Get the megabytes available in the filesystem at 'file'. * * @param file the filesystem's path.//from ww w . j av a 2 s . c o m * @return the available space in mb. */ public static float getAvailableMegabytes(File file) { StatFs stat = new StatFs(file.getPath()); long bytesAvailable = (long) stat.getBlockSize() * (long) stat.getAvailableBlocks(); return bytesAvailable / (1024.f * 1024.f); }