本文整理汇总了Java中android.os.StatFs.getBlockSize方法的典型用法代码示例。如果您正苦于以下问题:Java StatFs.getBlockSize方法的具体用法?Java StatFs.getBlockSize怎么用?Java StatFs.getBlockSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.StatFs
的用法示例。
在下文中一共展示了StatFs.getBlockSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAvailableExternalMemorySize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取手机外部可用空间大小,字节
*
* @return
*/
public static long getAvailableExternalMemorySize()
{
if (externalMemoryAvailable())
{
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return availableBlocks * blockSize;
}
else
{
return -1;
}
}
示例2: getSDAvailableSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 得到sd卡剩余大小
*
* @return
*/
public static long getSDAvailableSize() {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = 0;
long availableBlocks = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockSize = stat.getBlockSizeLong();
availableBlocks = stat.getAvailableBlocksLong();
} else {
blockSize = stat.getBlockSize();
availableBlocks = stat.getAvailableBlocks();
}
return blockSize * availableBlocks / 1024;
}
示例3: checkRomSpaceEnough
import android.os.StatFs; //导入方法依赖的package包/类
@Deprecated
public static boolean checkRomSpaceEnough(long limitSize) {
long allSize;
long availableSize = 0;
try {
StatFs sf = new StatFs(Environment.getDataDirectory().getPath());
availableSize = ((long) sf.getAvailableBlocks()) * ((long) sf.getBlockSize());
allSize = ((long) sf.getBlockCount()) * ((long) sf.getBlockSize());
} catch (Exception e) {
allSize = 0;
}
if (allSize == 0 || availableSize <= limitSize) {
return false;
}
return true;
}
示例4: getRootSubtitle
import android.os.StatFs; //导入方法依赖的package包/类
private String getRootSubtitle(String path) {
try {
StatFs stat = new StatFs(path);
long total = (long)stat.getBlockCount() * (long)stat.getBlockSize();
long free = (long)stat.getAvailableBlocks() * (long)stat.getBlockSize();
if (total == 0) {
return "";
}
return LocaleController.formatString("FreeOfTotal", R.string.FreeOfTotal, AndroidUtilities.formatFileSize(free), AndroidUtilities.formatFileSize(total));
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return path;
}
示例5: getRomAvailableSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获得机身可用内存rom
*
* @return
*/
public static long getRomAvailableSize() {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return blockSize * availableBlocks;
}
示例6: getSDSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取SD卡剩余空间的大小
*
* @return long SD卡剩余空间的大小(单位:byte)
*/
public static long getSDSize()
{
final String str = Environment.getExternalStorageDirectory().getPath();
final StatFs localStatFs = new StatFs(str);
final long blockSize = localStatFs.getBlockSize();
return localStatFs.getAvailableBlocks() * blockSize;
}
示例7: calculateDiskCacheSize
import android.os.StatFs; //导入方法依赖的package包/类
static long calculateDiskCacheSize(File dir) {
long size = MIN_DISK_CACHE_SIZE;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
long available = ((long) statFs.getBlockCount()) * statFs.getBlockSize();
size = available / 50;
} catch (IllegalArgumentException ignored) {
}
// return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
return 40772;
}
示例8: getFreeBytes
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取指定路径所在空间的剩余可用容量字节数(byte)
* @param filePath
* @return 容量字节 SDCard可用空间,内部存储可用空间
*/
public long getFreeBytes(String filePath) {
// 如果是sd卡的下的路径,则获取sd卡可用容量
if (filePath.startsWith(getSDCardPath())) {
filePath = getSDCardPath();
} else {// 如果是内部存储的路径,则获取内存存储的可用容量
filePath = Environment.getDataDirectory().getAbsolutePath();
}
StatFs stat = new StatFs(filePath);
long availableBlocks = (long) stat.getAvailableBlocks() - 4;
return stat.getBlockSize() * availableBlocks;
}
示例9: getDirTotalSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取目录空间总容量
*
* @param dirPath 目录路径
*
* @return 容量(Byte)
*/
public static long getDirTotalSize(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 countBlock;
if (Build.VERSION.SDK_INT < 18) {
countBlock = statFs.getBlockCount();
} else {
countBlock = statFs.getBlockCountLong();
}
return Math.abs(countBlock * blocSize);
} catch (Throwable e) {
DLog.e(e);
}
return 0;
}
示例10: calculateDiskCacheSize
import android.os.StatFs; //导入方法依赖的package包/类
private static long calculateDiskCacheSize(File dir) {
long size = 0;
try {
StatFs statFs = new StatFs(dir.getAbsolutePath());
long available = ((long) statFs.getBlockCount()) * statFs.getBlockSize();
size = available / 50;
} catch (IllegalArgumentException ignored) {
}
return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE);
}
示例11: getResidualSpace
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取目录剩余空间
*
* @param directoryPath
* @return
*/
private long getResidualSpace(String directoryPath) {
try {
StatFs sf = new StatFs(directoryPath);
long blockSize = sf.getBlockSize();
long availCount = sf.getAvailableBlocks();
long availCountByte = availCount * blockSize;
return availCountByte;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
示例12: e
import android.os.StatFs; //导入方法依赖的package包/类
public static long e() {
if (b()) {
return 0;
}
File externalStorageDirectory = Environment.getExternalStorageDirectory();
if (externalStorageDirectory == null || TextUtils.isEmpty(externalStorageDirectory
.getPath())) {
return 0;
}
StatFs statFs = new StatFs(externalStorageDirectory.getPath());
return (((long) statFs.getAvailableBlocks()) - 4) * ((long) statFs.getBlockSize());
}
示例13: getRomTotalSize
import android.os.StatFs; //导入方法依赖的package包/类
public static String getRomTotalSize(Context context) {
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
示例14: getFreeBytes
import android.os.StatFs; //导入方法依赖的package包/类
/**
* Gets the remaining number of bytes of available capacity in the space in the specified path, in units byte
*
* @param filePath file path
* @return Capacity bytes, SDCard, free space, internal storage, free space
*/
public static long getFreeBytes(String filePath) {
// If it is the next path of the SD card, the available capacity of the SD card is obtained.
if (filePath.startsWith(getSDCardPath())) {
filePath = getSDCardPath();
} else {// If the path is stored inside, the available capacity of obtaining memory.
filePath = Environment.getDataDirectory().getAbsolutePath();
}
StatFs stat = new StatFs(filePath);
long availableBlocks = (long) stat.getAvailableBlocks() - 4;
return stat.getBlockSize() * availableBlocks;
}
示例15: getUsableSpace
import android.os.StatFs; //导入方法依赖的package包/类
public static long getUsableSpace(File path) {
if (path == null) {
return -1;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
return path.getUsableSpace()/1024/1024;
} else {
if (!path.exists()) {
return 0;
} else {
final StatFs stats = new StatFs(path.getPath());
return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks()/1024/1024;
}
}
}