本文整理汇总了Java中android.os.StatFs.getBlockSizeLong方法的典型用法代码示例。如果您正苦于以下问题:Java StatFs.getBlockSizeLong方法的具体用法?Java StatFs.getBlockSizeLong怎么用?Java StatFs.getBlockSizeLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.StatFs
的用法示例。
在下文中一共展示了StatFs.getBlockSizeLong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasEnoughSpaceOnSdCard
import android.os.StatFs; //导入方法依赖的package包/类
/**
* Checks if there is enough Space on SDCard
*
* @param updateSize size to Check (long)
* @return <code>true</code> if the Update will fit on SDCard, <code>false</code> if not enough
* space on SDCard. Will also return <code>false</code>, if the SDCard is not mounted as
* read/write
*/
@SuppressWarnings("deprecation")
public boolean hasEnoughSpaceOnSdCard(long updateSize) {
RootTools.log("Checking SDcard size and that it is mounted as RW");
String status = Environment.getExternalStorageState();
if (!status.equals(Environment.MEDIA_MOUNTED)) {
return false;
}
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = 0;
long availableBlocks = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSize();
availableBlocks = stat.getAvailableBlocks();
} else {
blockSize = stat.getBlockSizeLong();
availableBlocks = stat.getAvailableBlocksLong();
}
return (updateSize < availableBlocks * blockSize);
}
示例2: getFreeStorageSpace
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 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;
}
示例3: getSDCardInfo
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取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();
}
示例4: getUsedSpace
import android.os.StatFs; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
@Override
public long getUsedSpace(SizeUnit sizeUnit) {
String path = buildAbsolutePath();
StatFs statFs = new StatFs(path);
long availableBlocks;
long blockSize;
long totalBlocks;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
availableBlocks = statFs.getAvailableBlocks();
blockSize = statFs.getBlockSize();
totalBlocks = statFs.getBlockCount();
} else {
availableBlocks = statFs.getAvailableBlocksLong();
blockSize = statFs.getBlockSizeLong();
totalBlocks = statFs.getBlockCountLong();
}
long usedBytes = totalBlocks * blockSize - availableBlocks * blockSize;
return usedBytes / sizeUnit.inBytes();
}
示例5: getPhoneTotalSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取手机内部存储总空间
*/
public static long getPhoneTotalSize() {
if (!checkSdCard()) {
File path = Environment.getDataDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long blockCountLong = mStatFs.getBlockCountLong();
return blockSizeLong * blockCountLong;
} else {
return getSDcardTotalSize();
}
}
示例6: getSDcardAvailableSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取SDka可用空间
*
* @return
*/
private static long getSDcardAvailableSize()
{
if (checkSdCard())
{
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long availableBlocksLong = mStatFs.getAvailableBlocksLong();
return blockSizeLong * availableBlocksLong;
} else
return 0;
}
示例7: getFreeSpace
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取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);
}
示例8: getSDcardAvailableSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取SDka可用空间
*/
private static long getSDcardAvailableSize() {
if (checkSdCard()) {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSizeLong = mStatFs.getBlockSizeLong();
long availableBlocksLong = mStatFs.getAvailableBlocksLong();
return blockSizeLong * availableBlocksLong;
} else {
return 0;
}
}
示例9: getAvailableStorage
import android.os.StatFs; //导入方法依赖的package包/类
public static long getAvailableStorage() {
try {
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}
} catch (RuntimeException ex) {
return 0;
}
}
示例10: getFreeSpace
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取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 ConvertUtils.byte2FitMemorySize(availableBlocks * blockSize);
}
示例11: getBlockSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* See {@link android.os.StatFs#getBlockSize()}.
*/
@SuppressWarnings("deprecation")
public static long getBlockSize(StatFs statFs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return statFs.getBlockSizeLong();
} else {
return statFs.getBlockSize();
}
}
示例12: getDirUsedSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取目录空间已用容量
*
* @param dirPath 目录路径
*
* @return 容量(Byte)
*/
public static long getDirUsedSize(String dirPath) {
try {
if (TextUtils.isEmpty(dirPath)) {
return 0;
}
StatFs statFs = new StatFs(dirPath);
// 获取单个数据块的大小(Byte)
long blocSize;
if (Build.VERSION.SDK_INT < 18) {
blocSize = statFs.getBlockSize();
} else {
blocSize = statFs.getBlockSizeLong();
}
// 获取所有数据块的数量
long totalBlocks;
if (Build.VERSION.SDK_INT < 18) {
totalBlocks = statFs.getBlockCount();
} else {
totalBlocks = statFs.getBlockCountLong();
}
// 获取空闲数据块的数量
long availableBlocks;
if (Build.VERSION.SDK_INT < 18) {
availableBlocks = statFs.getAvailableBlocks();
} else {
availableBlocks = statFs.getAvailableBlocksLong();
}
return Math.abs((totalBlocks - availableBlocks) * blocSize);
} catch (Throwable e) {
DLog.e(e);
}
return 0;
}
示例13: computeSpace
import android.os.StatFs; //导入方法依赖的package包/类
private void computeSpace() {
StatFs stat = new StatFs(mountPoint);
long bytesAvailable;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
bytesAvailable = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
//noinspection deprecation
bytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
}
// Convert total bytes to megabytes
freeSpace = Math.round(bytesAvailable / (1024 * 1024));
}
示例14: getFreeSpaceSize
import android.os.StatFs; //导入方法依赖的package包/类
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);
}
示例15: getSDCardInfo
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 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;
}