代码改变世界

获得内存卡的剩余内存

2012-06-20 11:28  htc开发  阅读(192)  评论(0编辑  收藏  举报
public static boolean hasStorageUsage() {
        File path = Environment.getDataDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSize();
        long availableBlocks = stat.getAvailableBlocks();
        float freeStorage = (availableBlocks * blockSize)/(1024 * 1024);
        if (freeStorage >= minStorageUsage) {
               return true;
        }
        return false;

    }

注:package android.os.StatFs.java;