/** * 获取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; }
时间: 2024-10-12 11:46:19