List of usage examples for android.os StatFs StatFs
public StatFs(String path)
From source file:Main.java
public static long[] getRomMemroy() { long[] romInfo = new long[2]; //Total rom memory romInfo[0] = getTotalInternalMemorySize(); //Available rom memory File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); romInfo[1] = blockSize * availableBlocks; return romInfo; }
From source file:Main.java
public static long getFreeDiskSpace() { String status = Environment.getExternalStorageState(); long freeSpace = 0; if (status.equals(Environment.MEDIA_MOUNTED)) { try {/*w ww . j a v a2s .c o m*/ 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(); } } else { return -1; } return (freeSpace); }
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 {/*from w w w.j av a 2 s. com*/ 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
/** * Calculates the total memory of the device. This is based on an inspection of the filesystem, which in android * devices is stored in RAM./* w w w . j a v a 2 s . c o m*/ * * @return Total number of bytes. */ public static long getTotalInternalMemorySize() { final File path = Environment.getDataDirectory(); final StatFs stat = new StatFs(path.getPath()); final long blockSize = stat.getBlockSize(); final long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static long getSDFreeSize() { File path = Environment.getExternalStorageDirectory(); if (path != null && path.exists() && path.isDirectory()) { StatFs sf = new StatFs(path.getPath()); long blockSize = sf.getBlockSizeLong(); long freeBlocks = sf.getAvailableBlocksLong(); return (freeBlocks * blockSize) / 1024 / 1024; }/* www . ja va 2s . com*/ return -1; }
From source file:Main.java
/** * Calculates the free memory of the device. This is based on an inspection of the filesystem, which in android * devices is stored in RAM.// www .j ava 2 s .c om * * @return Number of bytes available. */ public static long getAvailableInternalMemorySize() { final File path = Environment.getDataDirectory(); final StatFs stat = new StatFs(path.getPath()); final long blockSize = stat.getBlockSize(); final long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:Main.java
/** * Get the left size of the SDCard in Bytes. * //from w w w . ja v a 2 s . c o m * @return the left size */ @SuppressWarnings("deprecation") public static long getSDCardLeftSize() { File sdcard = Environment.getExternalStorageDirectory(); if (sdcard.exists()) { StatFs statFs = new StatFs(sdcard.getAbsolutePath()); long blockSize = statFs.getBlockSize(); long availableBlocks = statFs.getAvailableBlocks(); return blockSize * availableBlocks; } return 0; }
From source file:Main.java
@SuppressLint("NewApi") public static long getFreeDiskSpace() { String status = Environment.getExternalStorageState(); long freeSpace = 0; if (status.equals(Environment.MEDIA_MOUNTED)) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSizeLong(); long availableBlock = stat.getAvailableBlocksLong(); freeSpace = availableBlock * blockSize / 1024; } else {//from w ww.j av a 2 s . c om return -1; } return freeSpace; }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public static long getExternalStorageFreeMemory() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdAvailSize; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { sdAvailSize = (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong(); } else {/*from w w w. j ava 2 s .c o m*/ sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize(); } return Math.round(sdAvailSize / SIZE_MB); }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public static Boolean hasExternalStorageFreeMemory() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdAvailSize; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { sdAvailSize = (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong(); } else {//ww w .ja va2s. c o m sdAvailSize = (double) stat.getAvailableBlocks() * (double) stat.getBlockSize(); } return sdAvailSize >= 10 * SIZE_MB; }