當前位置: 首頁>>代碼示例>>Java>>正文


Java StatFs.getBlockSize方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:21,代碼來源:MIP_DeviceInfoUtils.java

示例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;
}
 
開發者ID:TAnsz,項目名稱:MyTvLauncher,代碼行數:21,代碼來源:Tools.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:Utils.java

示例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;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:15,代碼來源:DocumentSelectActivity.java

示例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;
}
 
開發者ID:waylife,項目名稱:ViewDebugHelper,代碼行數:13,代碼來源:SdCardUtils.java

示例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;
}
 
開發者ID:BaoBaoJianqiang,項目名稱:AndroidNetwork,代碼行數:13,代碼來源:BaseUtils.java

示例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;
    }
 
開發者ID:IstiN,項目名稱:android-training-2017,代碼行數:14,代碼來源:BaseDiskCache.java

示例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;
}
 
開發者ID:jopenbox,項目名稱:android-lite-utils,代碼行數:17,代碼來源:SDCardUtils.java

示例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;
}
 
開發者ID:youmi,項目名稱:nativead,代碼行數:37,代碼來源:FileUtils.java

示例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);
}
 
開發者ID:zhou-you,項目名稱:RxEasyHttp,代碼行數:11,代碼來源:RxCache.java

示例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;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:19,代碼來源:ExternalStorage.java

示例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());
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:13,代碼來源:c.java

示例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);
}
 
開發者ID:JackWHLiu,項目名稱:jackknife,代碼行數:8,代碼來源:IoUtils.java

示例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;
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:18,代碼來源:SDCardUtils.java

示例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;
        }
    }
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:16,代碼來源:FileUtils.java


注:本文中的android.os.StatFs.getBlockSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。