标签:
/** * 获取SD的信息的方法 */ private void getSd() { // TODO Auto-generated method stub File path=Environment.getExternalStorageDirectory(); StatFs stat=new StatFs(path.getPath()); long blockSize=stat.getBlockSize(); long totalBlacks=stat.getBlockCount(); long availableBlocks=stat.getAvailableBlocks(); long totalSize=blockSize*totalBlacks; long availSize=availableBlocks*blockSize; String totalStr=Formatter.formatFileSize(MainActivity.this, totalSize); String availStr=Formatter.formatFileSize(MainActivity.this, availSize); mTextViewShow.setText("Sd卡的总的容量是"+totalStr+"\n"+"SD卡的可用容量是"+availStr); }
//android获取手机内存的方法 /** * 获取手机内存的方法 * @return */ private String getRomSpaceInfo() { File path=Environment.getDataDirectory(); StatFs stat=new StatFs(path.getPath()); long blockSize=stat.getBlockSize(); long totalBlocks=stat.getBlockCount(); long availableBlocks=stat.getAvailableBlocks(); long totalSize=blockSize*totalBlocks; long availSize=availableBlocks*blockSize; String totalStr=Formatter.formatFileSize(MainActivity.this, totalSize); String availStr=Formatter.formatFileSize(MainActivity.this, availSize); return "手机的内存:总空间"+totalStr+"\n"+availStr; }
标签:
原文地址:http://www.cnblogs.com/dukc/p/4881001.html