Android 获取设备内存和外存

参考
Android 获取设备运行内存信息
https://blog.csdn.net/b1tb1t/article/details/131290808

Android 获取设备外存

	// 全部外存, 和手机标称不一样
    public static long getTotalStorage() {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSizeLong();
        long totalBlocks = stat.getBlockCountLong();
        return totalBlocks * blockSize;
    }

	// 可用外存
    public static long getAvailableStorage() {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = stat.getBlockSizeLong();
        long availableBlocks = stat.getAvailableBlocksLong();
        return availableBlocks * blockSize;
    }

你可能感兴趣的:(android)