List of usage examples for android.os StatFs getAvailableBlocks
@Deprecated public int getAvailableBlocks()
From source file:com.nd.pad.GreenBrowser.util.ImageDownloader.java
/** * // w w w .j ava2 s. com * @ : freeSpaceOnSd * @ : sdcard * @ * @return * * @ * @2012-10-20 12:18:41 * @ * */ private int freeSpaceOnSd() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); double sdFreeMB = ((double) stat.getAvailableBlocks() * (double) stat.getBlockSize()); return (int) sdFreeMB; }
From source file:com.adobe.phonegap.contentsync.Sync.java
private long getFreeSpace() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; }
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * ????./* www . j a v a2 s . c om*/ */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static long getDirSize(String path) { StatFs stat = new StatFs(path); long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= 18) { blockSize = stat.getBlockSizeLong(); availableBlocks = stat.getAvailableBlocksLong(); } else { blockSize = stat.getBlockSize(); availableBlocks = stat.getAvailableBlocks(); } return availableBlocks * blockSize; }
From source file:com.colorchen.qbase.utils.FileUtil.java
/** * ???./*from w ww. jav a2s .c o m*/ */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static long getSDCardAvailaleSize() { File path = getRootPath(); StatFs stat = new StatFs(path.getPath()); long blockSize, availableBlocks; if (Build.VERSION.SDK_INT >= 18) { blockSize = stat.getBlockSizeLong(); availableBlocks = stat.getAvailableBlocksLong(); } else { blockSize = stat.getBlockSize(); availableBlocks = stat.getAvailableBlocks(); } return availableBlocks * blockSize; }
From source file:com.miz.functions.MizLib.java
@SuppressWarnings("deprecation") public static long getFreeMemory() { StatFs stat = new StatFs(Environment.getDataDirectory().getPath()); if (hasJellyBeanMR2()) return stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); else//from w w w. j a v a 2 s . c om return stat.getAvailableBlocks() * stat.getBlockSize(); }
From source file:com.almalence.opencam.ApplicationScreen.java
protected long getAvailableInternalMemory() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize / 1048576; }
From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java
protected void warnIfStorageUnavailable() { if (!Util.isExternalStoragePresent()) { Util.toast(context, R.string.select_album_no_sdcard); }/* w w w . j a v a 2 s. co m*/ try { StatFs stat = new StatFs(FileUtil.getMusicDirectory(context).getPath()); long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); if (bytesAvailableFs < 50000000L) { Util.toast(context, context.getResources().getString(R.string.select_album_no_room, Util.formatBytes(bytesAvailableFs))); } } catch (Exception e) { Log.w(TAG, "Error while checking storage space for music directory", e); } }
From source file:com.android.mms.ui.MessageUtils.java
/** M: * Return the current storage status./*from w ww.j av a 2s . com*/ */ public static String getStorageStatus(Context context) { /// M: we need count only final String[] PROJECTION = new String[] { BaseColumns._ID, Mms.MESSAGE_SIZE }; final ContentResolver cr = context.getContentResolver(); final Resources res = context.getResources(); Cursor cursor = null; StringBuilder buffer = new StringBuilder(); // Mms count cursor = cr.query(Mms.CONTENT_URI, PROJECTION, null, null, null); int mmsCount = 0; if (cursor != null) { mmsCount = cursor.getCount(); } buffer.append(res.getString(R.string.storage_dialog_mms, mmsCount)); buffer.append("\n"); //Mms size long size = 0; if (cursor != null) { if (cursor.moveToFirst()) { do { size += cursor.getInt(1); } while (cursor.moveToNext()); } cursor.close(); } buffer.append(res.getString(R.string.storage_dialog_mms_size) + getHumanReadableSize(size)); buffer.append("\n"); // Attachment size size = getAttachmentSize(context); Log.d(TAG, "mms attachment size = " + size); final String sizeTag = getHumanReadableSize(size); buffer.append(res.getString(R.string.storage_dialog_attachments) + sizeTag); buffer.append("\n"); // Sms count cursor = cr.query(Sms.CONTENT_URI, PROJECTION, null, null, null); int smsCount = 0; if (cursor != null) { smsCount = cursor.getCount(); cursor.close(); } buffer.append(res.getString(R.string.storage_dialog_sms, smsCount)); buffer.append("\n"); // Database size final long dbsize = getDatabaseSize(context); buffer.append(res.getString(R.string.storage_dialog_database) + getHumanReadableSize(dbsize)); buffer.append("\n"); // Available space final StatFs datafs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); final long availableSpace = (long) datafs.getAvailableBlocks() * datafs.getBlockSize(); buffer.append( res.getString(R.string.storage_dialog_available_space) + getHumanReadableSize(availableSpace)); return buffer.toString(); }
From source file:com.android.mms.ui.MessageUtils.java
public static long getAvailableBytesInFileSystemAtGivenRoot(String rootFilePath) { StatFs stat = new StatFs(rootFilePath); // final long totalBlocks = stat.getBlockCount(); // put a bit of margin (in case creating the file grows the system by a few blocks) final long availableBlocks = stat.getAvailableBlocks() - 128; // long mTotalSize = totalBlocks * stat.getBlockSize(); long mAvailSize = availableBlocks * stat.getBlockSize(); Log.i(TAG, "getAvailableBytesInFileSystemAtGivenRoot(): " + "available space (in bytes) in filesystem rooted at: " + rootFilePath + " is: " + mAvailSize); return mAvailSize; }
From source file:com.android.gallery3d.app.PhotoPage.java
/** * get available space which storage source video is in. * * @return the available sapce size, -1 means max storage size. *//* ww w. java 2 s. c om*/ private long getAvailableSpace(String path) { // Here just use one directory to stat fs. StatFs stat = new StatFs(path); long availableSize = stat.getAvailableBlocks() * (long) stat.getBlockSize(); Log.i(TAG, "<getAvailableSpace> path " + path + ", availableSize(MB) " + (availableSize / STORAGE_CAPACITY_BASE / STORAGE_CAPACITY_BASE)); return availableSize; }