Java Code Examples for android.os.StatFs#getFreeBlocksLong()

The following examples show how to use android.os.StatFs#getFreeBlocksLong() . 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 vote down vote up
/**
 * 获取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: SDCardUtils.java    From XKnife-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 获取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 3
Source File: SDCardUtils.java    From Android-UtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * 获取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 4
Source File: StorageUtils.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
/**
 * 获取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: SdCardUtil.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source File: SDCardUtils.java    From zone-sdk with MIT License 6 votes vote down vote up
@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();
        }
    }
    LogZSDK.INSTANCE.i(sd.toString());
    return sd;
}
 
Example 7
Source File: StatFsHelper.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Gets the information about the free storage space, including reserved blocks, either internal
 * or external depends on the given input
 *
 * @param storageType Internal or external storage type
 * @return available space in bytes, -1 if no information is available
 */
@SuppressLint("DeprecatedMethod")
public long getFreeStorageSpace(StorageType storageType) {
  ensureInitialized();

  maybeUpdateStats();

  StatFs statFS = storageType == StorageType.INTERNAL ? mInternalStatFs : mExternalStatFs;
  if (statFS != null) {
    long blockSize, availableBlocks;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
      blockSize = statFS.getBlockSizeLong();
      availableBlocks = statFS.getFreeBlocksLong();
    } else {
      blockSize = statFS.getBlockSize();
      availableBlocks = statFS.getFreeBlocks();
    }
    return blockSize * availableBlocks;
  }
  return -1;
}
 
Example 8
Source File: FileUtil.java    From android-file-chooser with Apache License 2.0 6 votes vote down vote up
public static long readSDCard(Context context, Boolean isRemovable, Boolean freeOrTotal) {
    DecimalFormat df = new DecimalFormat("0.00");
    getStoragePath(context, isRemovable);
    StatFs sf = new StatFs(getStoragePath(context, isRemovable));
    long blockSize;
    long blockCount;
    long availCount;
    if (Build.VERSION.SDK_INT > 18) {
        blockSize = sf.getBlockSizeLong(); //文件存储时每一个存储块的大小为4KB
        blockCount = sf.getBlockCountLong();//存储区域的存储块的总个数
        availCount = sf.getFreeBlocksLong();//存储区域中可用的存储块的个数(剩余的存储大小)
    } else {
        blockSize = sf.getBlockSize();
        blockCount = sf.getBlockCount();
        availCount = sf.getFreeBlocks();
    }
    //Log.d("sss", "总的存储空间大小:" + blockSize * blockCount / 1073741824 + "GB" + ",剩余空间:"
    //    + availCount * blockSize / 1073741824 + "GB"
    //    + "--存储块的总个数--" + blockCount + "--一个存储块的大小--" + blockSize / 1024 + "KB");
    //return df.format((freeOrTotal ? availCount : blockCount) * blockSize / 1073741824.0);
    return (freeOrTotal ? availCount : blockCount) * blockSize;
    //return "-1";
}
 
Example 9
Source File: SdCardUtil.java    From LockDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
        }
    }

        Log.i(TAG, sd.toString());

    return sd;
}
 
Example 10
Source File: SDKUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static Long getFreeSpaceSize(StatFs statFs) {
    long freeSpaceSize = 0;
    try {
        if (VERSION.SDK_INT >= 18) {
            freeSpaceSize = statFs.getFreeBlocksLong() * statFs.getBlockSizeLong();
        } else {
            freeSpaceSize = ((long) statFs.getFreeBlocks()) * ((long) statFs.getBlockSize());
        }
    } catch (Throwable e) {
        LOG.w(TAG, "getScreenHeightWidth failed(Throwable): " + e.getMessage());
    }
    return Long.valueOf(freeSpaceSize);
}
 
Example 11
Source File: SdCardUtil.java    From android-common with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: RLAPICompat.java    From Roid-Library with Apache License 2.0 5 votes vote down vote up
public static long getFreeBlocks() {
    long size = 0;
    if (Environment.getExternalStorageDirectory() != null) {
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
        size = stat.getFreeBlocksLong();
    }
    return size;
}