Android获得内部/外部存储器的自由大小
我想以编程方式获取设备内部/外部存储上的可用内存大小。我正在使用这段代码: StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount(); long megAvailable = bytesAvailable / 1048576; Log.e("","Available MB : "+megAvailable); File path = Environment.getDataDirectory(); StatFs stat2 = new StatFs(path.getPath()); long blockSize = stat2.getBlockSize(); long availableBlocks = stat2.getAvailableBlocks(); String format = Formatter.formatFileSize(this, availableBlocks * blockSize); Log.e("","Format : "+format); 我得到的结果是: 11-15 …