Android获取当前可用内存
写入本地文件
private void getMemo(){
//获得ActivityManager服务的对象
ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
//获得MemoryInfo对象
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo() ;
//获得系统可用内存,保存在MemoryInfo对象上
mActivityManager.getMemoryInfo(memoryInfo) ;
long memSize = memoryInfo.availMem ;
selfHttpRequest.writeToLoacl(memSize+"");
Toast.makeText(this, "success", Toast.LENGTH_SHORT).show();
}
Toast形式
private void toastMemo(){
//获得ActivityManager服务的对象
ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
//获得MemoryInfo对象
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo() ;
//获得系统可用内存,保存在MemoryInfo对象上
mActivityManager.getMemoryInfo(memoryInfo) ;
long memSize = memoryInfo.availMem ;
double mem = memSize / (1000*1000);
Toast.makeText(this, mem+"MB ", Toast.LENGTH_SHORT).show();
}