大家好,希望你们都做得很好,伙计们,我有一个问题,如果我们使用adb shell cat /proc/meminfo来获取 RAM 大小,我们如何获得 android 设备的活动、非活动和有线内存使用情况我得到一个大字符串这里有活动和非活动记忆是相同的代码
ProcessBuilder cmd;
StringBuffer strMemory = new StringBuffer();
// final ActivityManager activityManager =(ActivityManager)
// context.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager actvityManager = (ActivityManager) this
.getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mInfo = new ActivityManager.MemoryInfo();
actvityManager.getMemoryInfo(mInfo);
strMemory.append("Available Memory : ");
strMemory.append(mInfo.availMem / 1048576L);
strMemory.append("\n");
strMemory.append("\n");
String result = strMemory.toString();
try {
String[] args = { "/system/bin/cat", "/proc/meminfo" };
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while (in.read(re) != -1) {
// System.out.println("itthhe ==== --- >>>> "+new
// String(re));
String str = new String(re);
// int a = Integer.parseInt(str);
System.out.println("oiiidd str 11111111111 --->>> " + str);
// Long aa = Long.parseLong(str)/1048576L;
String st = "Active";
System.out.println("oii0--->>>> "+st.substring(0,2));
int l1 = st.length();
if (l1 > 3) { l1 = 4; }
System.out.println("oiiidd str --->>> " + str);
if (str.startsWith(st.substring(0,l1)))
{
System.out.println(str+" -------------------printed dude ");
// do something..
}
result = result + new String(re);
}
in.close();
} catch (IOException ex) {
ex.printStackTrace();
}
return result;
现在从这里我得到大字符串
MemTotal: 256556 kB
MemFree: 93576 kB
Buffers: 1036 kB
Cached: 70064 kB
SwapCached: 0 kB
Active: 97496 kB
Inactive: 48828 kB
Active(anon): 79884 kB
Inactive(anon): 0 kB
Active(file): 17612 kB
Inactive(file): 48828 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 75244 kB
Mapped: 36340 kB
Slab: 4528 kB
SReclaimable: 1448 kB
SUnreclaim: 3080 kB
PageTables: 6864 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 128276 kB
Committed_AS: 1084956 kB
VmallocTotal: 712704 kB
VmallocUsed: 22596 kB
VmallocChunk: 684036 kB
现在我如何解析活动和非活动数据,
有没有其他方法可以找到,或者这是找到这些数据的唯一方法`