Java Code Examples for android.os.StatFs#getAvailableBlocksLong()
The following examples show how to use
android.os.StatFs#getAvailableBlocksLong() .
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 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 2
Source File: VDUtility.java From NewsMe with Apache License 2.0 | 6 votes |
@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 { 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; }
Example 3
Source File: RxFileTool.java From RxTools-master with Apache License 2.0 | 6 votes |
/** * 获取磁盘可用空间. */ @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; }
Example 4
Source File: CommonUtil.java From HeroVideo-master with Apache License 2.0 | 5 votes |
/** * 获取手机内存存储可用空间 * * @return */ public static long getPhoneAvailableSize() { if (!checkSdCard()) { File path = Environment.getDataDirectory(); StatFs mStatFs = new StatFs(path.getPath()); long blockSizeLong = mStatFs.getBlockSizeLong(); long availableBlocksLong = mStatFs.getAvailableBlocksLong(); return blockSizeLong * availableBlocksLong; } else return getSDcardAvailableSize(); }
Example 5
Source File: DiskStat.java From FileManager with Apache License 2.0 | 5 votes |
private void calculateInternalSpace() { File root = Environment.getRootDirectory(); StatFs sf = new StatFs(root.getPath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { mInternalBlockSize = sf.getBlockSizeLong(); mInternalBlockCount = sf.getBlockCountLong(); mInternalAvailableBlocks = sf.getAvailableBlocksLong(); } else { mInternalBlockSize = sf.getBlockSize(); mInternalBlockCount = sf.getBlockCount(); mInternalAvailableBlocks = sf.getAvailableBlocks(); } }
Example 6
Source File: IoUtils.java From Pioneer with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private static long getExtStorageAvailableApi18() { if (hasExtStorage()) { File extStorage = Environment.getExternalStorageDirectory(); StatFs sf = new StatFs(extStorage.getAbsolutePath()); return sf.getAvailableBlocksLong() * sf.getBlockSizeLong(); } return 0; }
Example 7
Source File: RxFileTool.java From RxTools-master with Apache License 2.0 | 5 votes |
/** * 获取SD卡剩余空间 * * @return SD卡剩余空间 */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static String getFreeSpace() { if (!isSDCardEnable()) return "sdcard unable!"; StatFs stat = new StatFs(getSDCardPath()); long blockSize, availableBlocks; availableBlocks = stat.getAvailableBlocksLong(); blockSize = stat.getBlockSizeLong(); return RxDataTool.byte2FitSize(availableBlocks * blockSize); }
Example 8
Source File: DiskUtil.java From lrkFM with MIT License | 5 votes |
/** * Calculates occupied space on disk * @param external If true will query external disk, otherwise will query internal disk. * @return Number of occupied mega bytes on disk. */ public static int busySpaceGibi(boolean external) { StatFs statFs = getStats(external); long total = (statFs.getBlockCountLong() * statFs.getBlockSizeLong()); long free = (statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong()); long used = (total - free) / GIBIBYTE; Log.d(TAG, "used disk space: " + String.valueOf(used/ GIBIBYTE)); return (int) used; }
Example 9
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 10
Source File: DiskUtil.java From lrkFM with MIT License | 5 votes |
/** * Calculates free space on disk * @param external If true will query external disk, otherwise will query internal disk. * @return Number of free mega bytes on disk. */ public static int freeSpaceGibi(boolean external) { StatFs statFs = getStats(external); long availableBlocks = statFs.getAvailableBlocksLong(); long blockSize = statFs.getBlockSizeLong(); long freeBytes = availableBlocks * blockSize; Log.d(TAG, "Free disk space: " + String.valueOf(freeBytes/ GIBIBYTE)); return (int) (freeBytes / GIBIBYTE); }
Example 11
Source File: SubsonicFragment.java From Audinaut with GNU General Public License v3.0 | 5 votes |
void warnIfStorageUnavailable() { if (!Util.isExternalStoragePresent()) { Util.toast(context, R.string.select_album_no_sdcard); } try { StatFs stat = new StatFs(FileUtil.getMusicDirectory(context).getPath()); long bytesAvailableFs = stat.getAvailableBlocksLong() * stat.getBlockSizeLong(); 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); } }
Example 12
Source File: ApiCompatibilityUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * See {@link android.os.StatFs#getAvailableBlocksLong}. */ @SuppressWarnings("deprecation") public static long getAvailableBlocks(StatFs statFs) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return statFs.getAvailableBlocksLong(); } else { return statFs.getAvailableBlocks(); } }
Example 13
Source File: DownloadRecordActivity.java From Dainty with Apache License 2.0 | 5 votes |
private void refreshStorageStatus() { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath()); long blockSize = statFs.getBlockSizeLong(); long totalBlocks = statFs.getBlockCountLong(); long availableBlocks = statFs.getAvailableBlocksLong(); String totalSize = Formatter.formatFileSize(this, blockSize * totalBlocks); String availableSize = Formatter.formatFileSize(this, blockSize * availableBlocks); textProgressBar.setTextAndProgress("内置存储可用:" + availableSize + "/共:" + totalSize, (int) ((float) availableBlocks / totalBlocks * 100)); } else { textProgressBar.setTextAndProgress("内置存储不可用", 0); } }
Example 14
Source File: Storage.java From android-storage with Apache License 2.0 | 5 votes |
public long getFreeSpace(String dir, SizeUnit sizeUnit) { StatFs statFs = new StatFs(dir); long availableBlocks; long blockSize; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { availableBlocks = statFs.getAvailableBlocks(); blockSize = statFs.getBlockSize(); } else { availableBlocks = statFs.getAvailableBlocksLong(); blockSize = statFs.getBlockSizeLong(); } long freeBytes = availableBlocks * blockSize; return freeBytes / sizeUnit.inBytes(); }
Example 15
Source File: SDCardUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 返回对应路径的空间大小信息 * @param path 路径 * @return long[], 0 = 总空间大小, 1 = 空闲空间大小, 2 = 已使用空间大小 */ public static long[] getBlockSizeInfos(final String path) { try { // 获取路径的存储空间信息 StatFs statFs = new StatFs(path); // 单个数据块的大小、数据块数量、空闲的数据块数量 long blockSize, blockCount, availableBlocks; // 版本兼容 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { blockSize = statFs.getBlockSizeLong(); blockCount = statFs.getBlockCountLong(); availableBlocks = statFs.getAvailableBlocksLong(); } else { blockSize = statFs.getBlockSize(); blockCount = statFs.getBlockCount(); availableBlocks = statFs.getAvailableBlocks(); } // 计算空间信息 long[] blocks = new long[3]; blocks[0] = blockSize * blockCount; blocks[1] = blockSize * availableBlocks; blocks[2] = ((blockCount - availableBlocks) * blockSize); // 返回空间信息 return blocks; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getBlockSizeInfos"); } return null; }
Example 16
Source File: Utilities.java From Android-Remote with GNU General Public License v3.0 | 5 votes |
/** * Get the free space on the external storage device (like sd card) * * @return The free space in byte */ @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static double getFreeSpaceExternal() { StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { return (double) stat.getAvailableBlocks() * (double) stat.getBlockSize(); } else { return (double) stat.getAvailableBlocksLong() * (double) stat.getBlockSizeLong(); } }
Example 17
Source File: SdCardUtils.java From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 获得sd卡剩余容量,即可用大小 * * @return */ public static long getSDAvailableSize() { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize =0; long availableBlocks=0; if(AppUtil.getSDKInt()>=18){ blockSize= stat.getBlockSizeLong(); availableBlocks=stat.getAvailableBlocksLong(); }else{ blockSize= stat.getBlockSize(); availableBlocks=stat.getAvailableBlocks(); } return blockSize * availableBlocks; }
Example 18
Source File: SDUtils.java From YCAudioPlayer with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static long getAvailableSize() { if (isMounted()) { StatFs stat = new StatFs(getSDCardPath()); // 获得可用的块的数量 long count = stat.getAvailableBlocksLong(); long size = stat.getBlockSizeLong(); return count * size; } return 0; }
Example 19
Source File: SDCardUtils.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
/** * 获取SD卡剩余空间 * * @return SD卡剩余空间 */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public static String getFreeSpace() { if (!isSDCardEnable()) return null; StatFs stat = new StatFs(getSDCardPath()); long blockSize, availableBlocks; availableBlocks = stat.getAvailableBlocksLong(); blockSize = stat.getBlockSizeLong(); return ConvertUtils.byte2FitMemorySize(availableBlocks * blockSize); }
Example 20
Source File: MedicAndroidJavascript.java From medic-android with GNU Affero General Public License v3.0 | 4 votes |
@org.xwalk.core.JavascriptInterface @android.webkit.JavascriptInterface public String getDeviceInfo() { try { if (activityManager == null) { return jsonError("ActivityManager not set. Cannot retrieve RAM info."); } if (connectivityManager == null) { return jsonError("ConnectivityManager not set. Cannot retrieve network info."); } String versionName = parent.getPackageManager() .getPackageInfo(parent.getPackageName(), 0) .versionName; JSONObject appObject = new JSONObject(); appObject.put("version", versionName); String androidVersion = Build.VERSION.RELEASE; int osApiLevel = Build.VERSION.SDK_INT; String osVersion = System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")"; JSONObject softwareObject = new JSONObject(); softwareObject .put("androidVersion", androidVersion) .put("osApiLevel", osApiLevel) .put("osVersion", osVersion); String device = Build.DEVICE; String model = Build.MODEL; String manufacturer = Build.BRAND; String hardware = Build.HARDWARE; Map<String, String> cpuInfo = getCPUInfo(); JSONObject hardwareObject = new JSONObject(); hardwareObject .put("device", device) .put("model", model) .put("manufacturer", manufacturer) .put("hardware", hardware) .put("cpuInfo", new JSONObject(cpuInfo)); File dataDirectory = Environment.getDataDirectory(); StatFs dataDirectoryStat = new StatFs(dataDirectory.getPath()); long dataDirectoryBlockSize = dataDirectoryStat.getBlockSizeLong(); long dataDirectoryAvailableBlocks = dataDirectoryStat.getAvailableBlocksLong(); long dataDirectoryTotalBlocks = dataDirectoryStat.getBlockCountLong(); long freeMemorySize = dataDirectoryAvailableBlocks * dataDirectoryBlockSize; long totalMemorySize = dataDirectoryTotalBlocks * dataDirectoryBlockSize; JSONObject storageObject = new JSONObject(); storageObject .put("free", freeMemorySize) .put("total", totalMemorySize); MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); activityManager.getMemoryInfo(memoryInfo); long totalRAMSize = memoryInfo.totalMem; long freeRAMSize = memoryInfo.availMem; long thresholdRAM = memoryInfo.threshold; JSONObject ramObject = new JSONObject(); ramObject .put("free", freeRAMSize) .put("total", totalRAMSize) .put("threshold", thresholdRAM); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); JSONObject networkObject = new JSONObject(); if (netInfo != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork()); int downSpeed = networkCapabilities.getLinkDownstreamBandwidthKbps(); int upSpeed = networkCapabilities.getLinkUpstreamBandwidthKbps(); networkObject .put("downSpeed", downSpeed) .put("upSpeed", upSpeed); } return new JSONObject() .put("app", appObject) .put("software", softwareObject) .put("hardware", hardwareObject) .put("storage", storageObject) .put("ram", ramObject) .put("network", networkObject) .toString(); } catch(Exception ex) { return jsonError("Problem fetching device info: ", ex); } }