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