本文整理汇总了Java中android.os.StatFs.getBlockCount方法的典型用法代码示例。如果您正苦于以下问题:Java StatFs.getBlockCount方法的具体用法?Java StatFs.getBlockCount怎么用?Java StatFs.getBlockCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.StatFs
的用法示例。
在下文中一共展示了StatFs.getBlockCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSDCardSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取SD卡全部内存空间大小
*
* @return
*/
public static long getSDCardSize() {
long blockCount;
long blockSize;
if (isSDCardMounted()) {
String dir = getSDCardBaseDir();
//StatFs是从C语言引过来的
StatFs statFs = new StatFs(dir);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
blockCount = statFs.getBlockCountLong();//有多少块
blockSize = statFs.getBlockSizeLong();//每块有多大
} else {
blockCount = statFs.getBlockCount();//有多少块
blockSize = statFs.getBlockSize();//每块有多大
}
return blockCount * blockSize / 1024 / 1024; //总大小
}
return 0;
}
示例2: t
import android.os.StatFs; //导入方法依赖的package包/类
public static String t(Context context) {
try {
if (a(context, "android.permission.WRITE_EXTERNAL_STORAGE")) {
String externalStorageState = Environment.getExternalStorageState();
if (externalStorageState == null || !externalStorageState.equals("mounted")) {
return null;
}
externalStorageState = Environment.getExternalStorageDirectory().getPath();
if (externalStorageState == null) {
return null;
}
StatFs statFs = new StatFs(externalStorageState);
long blockCount = (((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize
())) / 1000000;
return String.valueOf((((long) statFs.getBlockSize()) * ((long) statFs
.getAvailableBlocks())) / 1000000) + "/" + String.valueOf(blockCount);
}
f.warn("can not get the permission of android.permission.WRITE_EXTERNAL_STORAGE");
return null;
} catch (Object th) {
f.e(th);
return null;
}
}
示例3: getTotalSpaceByPath
import android.os.StatFs; //导入方法依赖的package包/类
public static long getTotalSpaceByPath(String path) {
Exception e;
if (TextUtils.isEmpty(path)) {
return -1;
}
File dir = new File(path);
if (!dir.exists()) {
dir.mkdir();
}
long block = 0;
long size = 0;
try {
StatFs statFs = new StatFs(path);
StatFs statFs2;
try {
block = (long) statFs.getBlockCount();
size = (long) statFs.getBlockSize();
statFs2 = statFs;
} catch (Exception e2) {
e = e2;
statFs2 = statFs;
e.printStackTrace();
return size * block;
}
} catch (Exception e3) {
e = e3;
e.printStackTrace();
return size * block;
}
return size * block;
}
示例4: ax
import android.os.StatFs; //导入方法依赖的package包/类
public static String ax() {
if (e(cC)) {
return cC;
}
StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
long blockCount = (((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) /
1000000;
StatFs statFs2 = new StatFs(Environment.getDataDirectory().getPath());
String str = String.valueOf((((long) statFs2.getAvailableBlocks()) * ((long) statFs2
.getBlockSize())) / 1000000) + "/" + String.valueOf(blockCount);
cC = str;
return str;
}
示例5: getInternalStorageSize
import android.os.StatFs; //导入方法依赖的package包/类
public static long getInternalStorageSize(Context context) {
long j = 0;
try {
String[] paths = (String[]) StorageManager.class.getMethod("getVolumePaths", new Class[0]).invoke((StorageManager) context.getSystemService("storage"), new Object[0]);
if (paths != null && paths.length >= 1) {
StatFs statFs = new StatFs(paths[0]);
j = ((((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / 1024) / 1024;
}
} catch (Exception e) {
LogTool.e(TAG, "getInternalStorageSize. " + e.toString());
}
return j;
}
示例6: getTotalSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获取SD卡总的容量
* @return 总容量;-1:SD卡不可用
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static long getTotalSize(){
if(isAvailable()){
StatFs statFs = new StatFs(getRootDirectory().getPath());
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1){
return statFs.getBlockCount() * statFs.getBlockSize();
}else{
return statFs.getBlockCount() * statFs.getBlockSize();
}
}else{
return -1;
}
}
示例7: getSDCardSize
import android.os.StatFs; //导入方法依赖的package包/类
public String getSDCardSize() {
long j = 0;
try {
if ("mounted".equals(Environment.getExternalStorageState())) {
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
j = ((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize());
}
} catch (Exception e) {
}
return String.valueOf(j);
}
示例8: getMinimumDelete
import android.os.StatFs; //导入方法依赖的package包/类
private long getMinimumDelete(List<File> files)
{
if (files.isEmpty())
{
return 0L;
}
long cacheSizeBytes = Util.getCacheSizeMB(context) * 1024L * 1024L;
long bytesUsedBySubsonic = 0L;
for (File file : files)
{
bytesUsedBySubsonic += file.length();
}
// Ensure that file system is not more than 95% full.
StatFs stat = new StatFs(files.get(0).getPath());
long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize();
long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
long bytesUsedFs = bytesTotalFs - bytesAvailableFs;
long minFsAvailability = bytesTotalFs - MIN_FREE_SPACE;
long bytesToDeleteCacheLimit = Math.max(bytesUsedBySubsonic - cacheSizeBytes, 0L);
long bytesToDeleteFsLimit = Math.max(bytesUsedFs - minFsAvailability, 0L);
long bytesToDelete = Math.max(bytesToDeleteCacheLimit, bytesToDeleteFsLimit);
Log.i(TAG, String.format("File system : %s of %s available", Util.formatBytes(bytesAvailableFs), Util.formatBytes(bytesTotalFs)));
Log.i(TAG, String.format("Cache limit : %s", Util.formatBytes(cacheSizeBytes)));
Log.i(TAG, String.format("Cache size before : %s", Util.formatBytes(bytesUsedBySubsonic)));
Log.i(TAG, String.format("Minimum to delete : %s", Util.formatBytes(bytesToDelete)));
return bytesToDelete;
}
示例9: getSDTotalSize
import android.os.StatFs; //导入方法依赖的package包/类
private String getSDTotalSize()
{
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
}
示例10: getRomTotalSize
import android.os.StatFs; //导入方法依赖的package包/类
/**
* 获得机身内存总大小
*
* @return
*/
private String getRomTotalSize()
{
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
return Formatter.formatFileSize(SimpleActivity.this, blockSize * totalBlocks);
}
示例11: 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);
}
示例12: 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;
}
示例13: calculateDiskCacheSize
import android.os.StatFs; //导入方法依赖的package包/类
private static long calculateDiskCacheSize(File dir) {
long size = 0;
try {
if (!dir.exists()) {
dir.mkdirs();
}
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);
}
示例14: getSdcardTotalSpace
import android.os.StatFs; //导入方法依赖的package包/类
public static long getSdcardTotalSpace() {
Exception e;
if (!isSdcardAvailable()) {
return -1;
}
String sdcardPath = getDownloadDir().getAbsolutePath();
File dir = new File(sdcardPath);
if (!dir.exists()) {
dir.mkdirs();
}
long block = 0;
long size = 0;
try {
StatFs statFs = new StatFs(sdcardPath);
StatFs statFs2;
try {
block = (long) statFs.getBlockCount();
size = (long) statFs.getBlockSize();
statFs2 = statFs;
} catch (Exception e2) {
e = e2;
statFs2 = statFs;
e.printStackTrace();
return size * block;
}
} catch (Exception e3) {
e = e3;
e.printStackTrace();
return size * block;
}
return size * block;
}
示例15: getBlockCount
import android.os.StatFs; //导入方法依赖的package包/类
/**
* See {@link android.os.StatFs#getBlockCount()}.
*/
@SuppressWarnings("deprecation")
public static long getBlockCount(StatFs statFs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return statFs.getBlockCountLong();
} else {
return statFs.getBlockCount();
}
}