130|root@android:/ # cat proc/meminfo
MemTotal: 1006424 kB //内存总大小
MemFree: 313444 kB //空闲内存
Buffers: 0 kB
//test ddr//
private String getAvailMemory() {// 获取android当前可用内存大小
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
am.getMemoryInfo(mi);
//mi.availMem; 当前系统的可用内存
return Formatter.formatFileSize(getBaseContext(), mi.availMem);// 将获取的内存大小规格化
}
private String getTotalMemory() {
String str1 = "/proc/meminfo";// 系统内存信息文件
String str2;
String[] arrayOfString;
long initial_memory = 0;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(
localFileReader, 8192);
str2 = localBufferedReader.readLine();// 读取meminfo第一行,系统总内存大小
str2=str2.replace(" ", "");
str2=str2.replace("kB", "");
arrayOfString = str2.split(":");
for (String num : arrayOfString) {
Log.i(str2, num + "/t");
}
initial_memory = Integer.valueOf(arrayOfString[1]).intValue() * 1024;// 获得系统总内存,单位是KB,乘以1024转换为Byte
localBufferedReader.close();
} catch (IOException e) {
}
return Formatter.formatFileSize(getBaseContext(), initial_memory);// Byte转换为KB或者MB,内存大小规格化
}
private void testmem(){
Toast toast = Toast.makeText(getApplicationContext(),"手机总内存: " + this.getTotalMemory() + ", " + "可用内存: "+ this.getAvailMemory(), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
/