Java Code Examples for android.os.StatFs#getAvailableBytes()
The following examples show how to use
android.os.StatFs#getAvailableBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SDCardUtils.java From Android-UtilCode with Apache License 2.0 | 6 votes |
/** * 获取SD卡信息 * * @return SDCardInfo */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static String getSDCardInfo() { if (!isSDCardEnable()) return null; SDCardInfo sd = new SDCardInfo(); sd.isExist = true; StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); return sd.toString(); }
Example 2
Source File: Storage.java From batteryhub with Apache License 2.0 | 6 votes |
/** * Returns free and total storage space in bytes * * @param path Path to the storage medium * @return Free and total space in long[] */ @Deprecated private static long[] getStorageDetailsForPath(File path) { if (path == null) return new long[]{}; final int KB = 1024; final int MB = KB * 1024; long free; long total; long blockSize; try { StatFs stats = new StatFs(path.getAbsolutePath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { free = stats.getAvailableBytes() / MB; total = stats.getTotalBytes() / MB; return new long[]{free, total}; } else { blockSize = (long) stats.getBlockSize(); free = ((long) stats.getAvailableBlocks() * blockSize) / MB; total = ((long) stats.getBlockCount() * blockSize) / MB; if (free < 0 || total < 0) return new long[]{}; return new long[]{free, total}; } } catch (Exception e) { return new long[]{}; } }
Example 3
Source File: SdCardUtil.java From AndroidBase with Apache License 2.0 | 6 votes |
/** * Get SD card info detail. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static SDCardInfo getSDCardInfo() { SDCardInfo sd = new SDCardInfo(); String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { sd.isExist = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { File sdcardDir = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(sdcardDir.getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); } } LogUtils.i( sd.toString()); return sd; }
Example 4
Source File: StorageUtils.java From SprintNBA with Apache License 2.0 | 6 votes |
/** * 获取SD卡信息 * * @return */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static SDCardInfo getSDCardInfo() { SDCardInfo sd = new SDCardInfo(); String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { sd.isExist = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { File sdcardDir = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(sdcardDir.getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); } } LogUtils.i(TAG, sd.toString()); return sd; }
Example 5
Source File: StorageActivity.java From AndroidDemo with MIT License | 6 votes |
/** * 除去系统后的内存大小 */ private void checkExceptSystemCapacity() { StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath()); //存储块 long blockCount = statFs.getBlockCount(); //块大小 long blockSize = statFs.getBlockSize(); //可用块数量 long availableCount = statFs.getAvailableBlocks(); //剩余块数量,注:这个包含保留块(including reserved blocks)即应用无法使用的空间 long freeBlocks = statFs.getFreeBlocks(); long totalSize = statFs.getTotalBytes(); long availableSize = statFs.getAvailableBytes(); append("total = " + getUnit(totalSize)); append("availableSize = " + getUnit(availableSize)); append("========="); append("total = " + getUnit(blockSize * blockCount)); append("available = " + getUnit(blockSize * availableCount)); append("free = " + getUnit(blockSize * freeBlocks)); }
Example 6
Source File: SDCardUtils.java From XKnife-Android with Apache License 2.0 | 6 votes |
/** * 获取SD卡信息 * * @return SDCardInfo sd card info */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static String getSDCardInfo() { SDCardInfo sd = new SDCardInfo(); if (!isSDCardEnable()) return "sdcard unable!"; sd.isExist = true; StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); return sd.toString(); }
Example 7
Source File: OBAnalyticsManagerOnline.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
@Override public void deviceStorageUse () { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = stat.getAvailableBytes(); long bytesTotal = stat.getTotalBytes(); // long megaBytesAvailable = bytesAvailable / (1024 * 1024); long megaBytesTotal = bytesTotal / (1024 * 1024); long megaBytesUsed = megaBytesTotal - megaBytesAvailable; // Map<String, Object> parameters = new HashMap(); parameters.put(OBAnalytics.Params.DEVICE_USED_STORAGE, Long.valueOf(megaBytesUsed)); parameters.put(OBAnalytics.Params.DEVICE_TOTAL_STORAGE, Long.valueOf(megaBytesTotal)); // logEvent(OBAnalytics.Event.DEVICE, parameters); }
Example 8
Source File: OBAnalyticsManagerCommunity.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
@Override public void deviceStorageUse () { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = stat.getAvailableBytes(); long bytesTotal = stat.getTotalBytes(); // long megaBytesAvailable = bytesAvailable / (1024 * 1024); long megaBytesTotal = bytesTotal / (1024 * 1024); long megaBytesUsed = megaBytesTotal - megaBytesAvailable; // deviceStatusValues.put(OBAnalytics.Params.DEVICE_USED_STORAGE, Long.valueOf(megaBytesUsed)); deviceStatusValues.put(OBAnalytics.Params.DEVICE_TOTAL_STORAGE, Long.valueOf(megaBytesTotal)); /* * Value is now stored in a buffer for regular updates to the database * Map<String, Object> parameters = new HashMap(); parameters.put(OBAnalytics.Params.DEVICE_USED_STORAGE, Long.valueOf(megaBytesUsed)); parameters.put(OBAnalytics.Params.DEVICE_TOTAL_STORAGE, Long.valueOf(megaBytesTotal)); // logEvent(OBAnalytics.Event.DEVICE, parameters); */ }
Example 9
Source File: HttpApiBase.java From iview-android-tv with MIT License | 6 votes |
@SuppressWarnings("deprecation") private static long calculateAvailableCacheSize(File dir) { long size = 0; try { StatFs statFs = new StatFs(dir.getAbsolutePath()); int sdkInt = Build.VERSION.SDK_INT; long totalBytes; long availableBytes; if (sdkInt < Build.VERSION_CODES.JELLY_BEAN_MR2) { int blockSize = statFs.getBlockSize(); availableBytes = ((long) statFs.getAvailableBlocks()) * blockSize; totalBytes = ((long) statFs.getBlockCount()) * blockSize; } else { availableBytes = statFs.getAvailableBytes(); totalBytes = statFs.getTotalBytes(); } size = (long) Math.min(availableBytes * MAX_AVAILABLE_SPACE_USE_FRACTION, totalBytes * MAX_TOTAL_SPACE_USE_FRACTION); } catch (IllegalArgumentException ignored) { // ignored } return size; }
Example 10
Source File: APDE.java From APDE with GNU General Public License v2.0 | 6 votes |
public static String getAvailableSpace(File drive) { try { StatFs stat = new StatFs(drive.getAbsolutePath()); DecimalFormat df = new DecimalFormat("#.00"); df.setRoundingMode(RoundingMode.HALF_UP); long available; long total; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { available = stat.getAvailableBytes(); total = stat.getTotalBytes(); } else { available = stat.getAvailableBlocks() * stat.getBlockSize(); total = stat.getBlockCount() * stat.getBlockSize(); } return df.format(available / BYTE_PER_GB) + " GB free of " + df.format(total / BYTE_PER_GB) + " GB"; } catch (IllegalArgumentException e) { return "Failed to stat FS"; } }
Example 11
Source File: SDCardUtils.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
/** * 获取SD卡信息 * * @return SDCardInfo */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static String getSDCardInfo() { if (!isSDCardEnable()) return null; SDCardInfo sd = new SDCardInfo(); sd.isExist = true; StatFs sf = new StatFs(Environment.getExternalStorageDirectory().getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); return sd.toString(); }
Example 12
Source File: FileDownloadUtils.java From okdownload with Apache License 2.0 | 5 votes |
public static long getFreeSpaceBytes(final String path) { long freeSpaceBytes; final StatFs statFs = new StatFs(path); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { freeSpaceBytes = statFs.getAvailableBytes(); } else { //noinspection deprecation freeSpaceBytes = statFs.getAvailableBlocks() * (long) statFs.getBlockSize(); } return freeSpaceBytes; }
Example 13
Source File: Util.java From okdownload with Apache License 2.0 | 5 votes |
public static long getFreeSpaceBytes(@NonNull StatFs statFs) { // NEED CHECK PERMISSION? long freeSpaceBytes; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { freeSpaceBytes = statFs.getAvailableBytes(); } else { //noinspection deprecation freeSpaceBytes = statFs.getAvailableBlocks() * (long) statFs.getBlockSize(); } return freeSpaceBytes; }
Example 14
Source File: Util.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@SuppressLint("NewApi") public static long getAvailableInternalMemorySize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long ret; if (android.os.Build.VERSION.SDK_INT < 18) { long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); ret = availableBlocks * blockSize; } else { ret = stat.getAvailableBytes(); } EventCollector.collectSessionData("FreeInternalMemorySize", Long.toString(ret)); return ret; }
Example 15
Source File: DeviceUtils.java From MyUtil with Apache License 2.0 | 5 votes |
/** * 获取手机内部存储剩余空间 单位byte * @return */ @SuppressWarnings("deprecation") public static long getAvailableInternalStorageSize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); if(Build.VERSION.SDK_INT >= 18) { return stat.getAvailableBytes(); } else { return (long) stat.getAvailableBlocks() * stat.getBlockSize(); } }
Example 16
Source File: DeviceUtils.java From MyUtil with Apache License 2.0 | 5 votes |
/** * 获取SDCARD剩余存储空间 单位byte * @return */ public static long getAvailableExternalStorageSize() { if (isSdcardExisting()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); if(Build.VERSION.SDK_INT >= 18) { return stat.getAvailableBytes(); } else { return (long) stat.getAvailableBlocks() * stat.getBlockSize(); } } else { return 0L; } }
Example 17
Source File: SdCardUtil.java From android-common with Apache License 2.0 | 5 votes |
/** * Get SD card info detail. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static SDCardInfo getSDCardInfo() { SDCardInfo sd = new SDCardInfo(); String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { sd.isExist = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { File sdcardDir = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(sdcardDir.getPath()); sd.totalBlocks = sf.getBlockCountLong(); sd.blockByteSize = sf.getBlockSizeLong(); sd.availableBlocks = sf.getAvailableBlocksLong(); sd.availableBytes = sf.getAvailableBytes(); sd.freeBlocks = sf.getFreeBlocksLong(); sd.freeBytes = sf.getFreeBytes(); sd.totalBytes = sf.getTotalBytes(); } } if (Log.isPrint) { Log.i(TAG, sd.toString()); } return sd; }
Example 18
Source File: FileUtils.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * sd卡容量 * * @return */ public static long getAvailableStorage() { long availableSize = 0; if (isSDCardExist()) { File sdFile = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(sdFile.getPath()); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2) { availableSize = stat.getAvailableBytes(); } else { availableSize = ((long) stat.getAvailableBlocks() * stat.getBlockSize()); } } return availableSize; }
Example 19
Source File: UpdateMenuItemHelper.java From delion with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private static long getSizeUpdatedApi(StatFs statFs) { return statFs.getAvailableBytes() / (1024 * 1024); }
Example 20
Source File: UpdateMenuItemHelper.java From AndroidChromium with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private static long getSizeUpdatedApi(StatFs statFs) { return statFs.getAvailableBytes() / (1024 * 1024); }