Android之获得内存剩余大小与总大小
2012-11-23 16:08
495 查看
public class memInfo {
// 获得可用的内存
public static long getmem_UNUSED(Context mContext) {
long MEM_UNUSED;
// 得到ActivityManager
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); // 创建ActivityManager.MemoryInfo对象
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 取得剩余的内存空间
MEM_UNUSED = mi.availMem / 1024;
return MEM_UNUSED;
}
// 获得总内存
public static long getmem_TOLAL() {
long mTotal;
// /proc/meminfo读出的内核信息进行解释
String path = "/proc/meminfo";
String content = null;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(path), 8);
String line;
if ((line = br.readLine()) != null) {
content = line;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// beginIndex
int begin = content.indexOf(':');
// endIndex
int end = content.indexOf('k');
// 截取字符串信息
content = content.substring(begin + 1, end).trim();
mTotal = Integer.parseInt(content);
return mTotal;
}
}
// 获得可用的内存
public static long getmem_UNUSED(Context mContext) {
long MEM_UNUSED;
// 得到ActivityManager
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); // 创建ActivityManager.MemoryInfo对象
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
// 取得剩余的内存空间
MEM_UNUSED = mi.availMem / 1024;
return MEM_UNUSED;
}
// 获得总内存
public static long getmem_TOLAL() {
long mTotal;
// /proc/meminfo读出的内核信息进行解释
String path = "/proc/meminfo";
String content = null;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(path), 8);
String line;
if ((line = br.readLine()) != null) {
content = line;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// beginIndex
int begin = content.indexOf(':');
// endIndex
int end = content.indexOf('k');
// 截取字符串信息
content = content.substring(begin + 1, end).trim();
mTotal = Integer.parseInt(content);
return mTotal;
}
}
相关文章推荐
- Android之获得内存剩余大小与总大小
- Android之获得内存剩余大小与总大小
- Android之获得内存剩余大小与总大小
- Android之获得可用内存大小
- 获得Android系统的唯一标识、android版本、网络接入方式、当前网络接入方式的MAC地址、IP、CPU的利用率、CPU的负载、内存大小
- Android 获取app应用大小、手机内存信息、删除文件方法、获得文件大小
- 通过free命令获得系统剩余的内存大小
- 在vc中获得windows系统信息,硬盘剩余容量,内存大小
- Android 获得sdcard大小与内存大小工具类
- Android编程实现获得内存剩余大小与总大小的方法
- android获得sd卡和本机内存大小
- Android获得手机内存和SD卡空间大小
- Android中StatFs获取系统/sdcard存储(剩余空间)大小
- Android获取内部和外部内存空间大小
- Android Studio的内存大小设置
- Android中列出手机的所有应用和剩余内存使用情况
- Linux:centos释放缓存,查看磁盘空间大小,xxx文件夹, 查看文件夹大小,查看剩余内存,查看xxx软件位置,统计某文件夹,统计某文件夹下目录数量,查看文件夹大小,给文件夹下所有的文件赋值权限
- Android 获得图片并解码成缩略图以减少内存消耗
- Cocos2d-x使用android拍照功能加载照片内存过大,通过另存照片尺寸大小解决
- Android中StatFs获取系统/sdcard存储(剩余空间)大小