//获取sd的信息
File file = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(file.getPath());
long blockSize = stat.getBlockSize();//获取每个Block的大小
long totalBlocks = stat.getBlockCount();//获取Block的总数
long availiableBlocks = stat.getAvailableBlocks();//获取可以使用的Block数目
String totalStr = android.text.format.Formatter
.formatFileSize(MainActivity.this, totalBlocks * blockSize) ;
String availiableStr = android.text.format.Formatter
.formatFileSize(MainActivity.this, availiableBlocks * blockSize) ;
Toast.makeText(MainActivity.this, "总内存:" + totalStr + ",剩余内存:" + availiableStr, Toast.LENGTH_LONG).show();
Android杂谈之获取sdcard信息
最新推荐文章于 2016-11-04 15:23:59 发布