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


Java StatFs.getAvailableBlocks方法代碼示例

本文整理匯總了Java中android.os.StatFs.getAvailableBlocks方法的典型用法代碼示例。如果您正苦於以下問題:Java StatFs.getAvailableBlocks方法的具體用法?Java StatFs.getAvailableBlocks怎麽用?Java StatFs.getAvailableBlocks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.StatFs的用法示例。


在下文中一共展示了StatFs.getAvailableBlocks方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUsedSpace

import android.os.StatFs; //導入方法依賴的package包/類
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
@Override
public long getUsedSpace(SizeUnit sizeUnit) {
	String path = buildAbsolutePath();
	StatFs statFs = new StatFs(path);
	long availableBlocks;
	long blockSize;
	long totalBlocks;
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
		availableBlocks = statFs.getAvailableBlocks();
		blockSize = statFs.getBlockSize();
		totalBlocks = statFs.getBlockCount();
	} else {
		availableBlocks = statFs.getAvailableBlocksLong();
		blockSize = statFs.getBlockSizeLong();
		totalBlocks = statFs.getBlockCountLong();
	}
	long usedBytes = totalBlocks * blockSize - availableBlocks * blockSize;
	return usedBytes / sizeUnit.inBytes();
}
 
開發者ID:chemickypes,項目名稱:Glitchy,代碼行數:22,代碼來源:AbstractDiskStorage.java

示例2: getSDCardAvailableSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * 獲取SD卡可用剩餘空間大小(還剩下多少空間)
 *
 * @return
 */
public static long getSDCardAvailableSize() {

    long availableBlockCount;
    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) {
            availableBlockCount = statFs.getAvailableBlocksLong();//有多少塊
            blockSize = statFs.getBlockSizeLong();//每塊有多大
        } else {
            availableBlockCount = statFs.getAvailableBlocks();//有多少塊
            blockSize = statFs.getBlockSize();//每塊有多大
        }

        return availableBlockCount * blockSize / 1024 / 1024; //總大小
    }
    return 0;
}
 
開發者ID:CodingCodersCode,項目名稱:EvolvingNetLib,代碼行數:28,代碼來源:SDCardUtil.java

示例3: getAvailableBytes

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * Return number of available bytes on the filesystem backing the given
 * {@link FileDescriptor}, minus any {@link #RESERVED_BYTES} buffer.
 */
private static long getAvailableBytes(FileDescriptor fd) throws IOException {
    try {
        //TODO only Sdcard check??
        String sdcardDir = Environment.getExternalStorageDirectory().getPath();
        StatFs stat = new StatFs(sdcardDir);
        long bytesAvailable = 0;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
            bytesAvailable = (long)stat.getBlockSizeLong() * (long)stat.getAvailableBlocksLong();
        } else {
            bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
        }
        return bytesAvailable - RESERVED_BYTES;
    } catch (Exception e) {
        throw new  IOException("getAvailableBytes IOException");
    }
}
 
開發者ID:limpoxe,項目名稱:Android-DownloadManager,代碼行數:21,代碼來源:StorageUtils.java

示例4: getFreeSpace

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * 獲得可用存儲空間
 *
 * @return 可用存儲空間(單位b)
 */
public long getFreeSpace() {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize;//區塊的大小
    long totalBlocks;//區塊總數
    long availableBlocks;//可用區塊的數量
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        blockSize = stat.getBlockSizeLong();
        totalBlocks = stat.getBlockCountLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        blockSize = stat.getBlockSize();
        totalBlocks = stat.getBlockCount();
        availableBlocks = stat.getAvailableBlocks();
    }
    Log.e(TAG, "totalSpace:" + blockSize * totalBlocks + "...availableSpace:" + blockSize * availableBlocks);
    return blockSize * availableBlocks;
}
 
開發者ID:mChenys,項目名稱:AndroidFFmpegCompress,代碼行數:24,代碼來源:MainActivity.java

示例5: getAvailableInternalDataSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * @return The available storage in MegaBytes
 */
@SuppressWarnings("deprecation")
public static Long getAvailableInternalDataSize() {
    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
    long size = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    return size / AirSdcard.BYTES_TO_MB;
}
 
開發者ID:yongbeam,項目名稱:AirQuickUtils,代碼行數:10,代碼來源:AirSystem.java

示例6: getFreeSpaceBytes

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * 獲取空閑的空間大小
 * @param path  文件路徑
 * @return  空間大小
 */
public static long getFreeSpaceBytes(final String path) {
    long freeSpaceBytes;
    final StatFs statFs = new StatFs(path);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        freeSpaceBytes = statFs.getAvailableBytes();
    } else {
        //noinspection deprecation
        freeSpaceBytes = statFs.getAvailableBlocks() * (long) statFs.getBlockSize();
    }

    return freeSpaceBytes;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:SDCardUtils.java

示例7: b

import android.os.StatFs; //導入方法依賴的package包/類
public static d b(File file) {
    d dVar = new d();
    dVar.a(file);
    StatFs statFs = new StatFs(file.getAbsolutePath());
    long blockSize = (long) statFs.getBlockSize();
    long availableBlocks = (long) statFs.getAvailableBlocks();
    dVar.a(((long) statFs.getBlockCount()) * blockSize);
    dVar.b(blockSize * availableBlocks);
    return dVar;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:11,代碼來源:d.java

示例8: 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

示例9: getSDAvailableSize

import android.os.StatFs; //導入方法依賴的package包/類
private String getSDAvailableSize()
{
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return Formatter.formatFileSize(this, blockSize * availableBlocks);
}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:9,代碼來源:FxService.java

示例10: 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

示例11: getDirSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * 獲取某個目錄可用大小.
 */
@SuppressLint({"NewApi", "ObsoleteSdkInt"})
@SuppressWarnings("deprecation")
public static long getDirSize(String path) {
    StatFs stat = new StatFs(path);
    long blockSize, availableBlocks;
    if (Build.VERSION.SDK_INT >= 18) {
        blockSize = stat.getBlockSizeLong();
        availableBlocks = stat.getAvailableBlocksLong();
    } else {
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();
    }
    return availableBlocks * blockSize;
}
 
開發者ID:ChunweiDu,項目名稱:Utils,代碼行數:18,代碼來源:FileUtil.java

示例12: getFreeSpaceInBytes

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * Given a path return the number of free bytes in the filesystem containing the path.
 *
 * @param path to the file system
 * @return free space in bytes
 */
public static long getFreeSpaceInBytes(String path) {
    try {
        StatFs stat = new StatFs(path);
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        return availableBlocks * blockSize;
    } catch (IllegalArgumentException e) {
        // The path was invalid. Just return 0 free bytes.
        return 0;
    }
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:18,代碼來源:DirectoryManager.java

示例13: getAvailableStorage

import android.os.StatFs; //導入方法依賴的package包/類
public static long getAvailableStorage() {
    try {
        StatFs stat = new StatFs(Environment.getExternalStorageDirectory().toString());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
        } else {
            return (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
        }
    } catch (RuntimeException ex) {
        return 0;
    }
}
 
開發者ID:Justson,項目名稱:AgentWebX5,代碼行數:13,代碼來源:AgentWebX5Utils.java

示例14: computeSpace

import android.os.StatFs; //導入方法依賴的package包/類
private void computeSpace() {
    StatFs stat = new StatFs(mountPoint);
    long bytesAvailable;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
        bytesAvailable = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
    } else {
        //noinspection deprecation
        bytesAvailable = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize();
    }
    // Convert total bytes to megabytes
    freeSpace = Math.round(bytesAvailable / (1024 * 1024));
}
 
開發者ID:fekracomputers,項目名稱:IslamicLibraryAndroid,代碼行數:13,代碼來源:StorageUtils.java

示例15: getSDCardAllSize

import android.os.StatFs; //導入方法依賴的package包/類
/**
 * Gets the remaining capacity unit of SD card byte
 *
 * @return Remaining capacity unit of SD card byte
 */
public static long getSDCardAllSize() {
    if (isSDCardEnable()) {
        StatFs stat = new StatFs(getSDCardPath());
        // Gets the number of free blocks of data
        long availableBlocks = (long) stat.getAvailableBlocks() - 4;
        // Gets the size of a single block of data (byte)
        long freeBlocks = stat.getAvailableBlocks();
        return freeBlocks * availableBlocks;
    }
    return 0;
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:17,代碼來源:SDCardUtils.java


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