本文整理匯總了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();
}
}