之前在百度看了好几多资料,耐烦出现好多坑,估计是时间太久了,导致不适用,现在我贴上我的代码,大家看一下,本人已通过编译,可以正常运行
public static String[] getHeap(String packageName) {
String cmd = "adb shell dumpsys meminfo " + packageName;
String PSS = null;
String Native = null;
String Dalvik = null;
Process p = null;
try {
p = Runtime.getRuntime().exec(cmd);
InputStream in = p.getInputStream();
BufferedReader bReader = new BufferedReader(new InputStreamReader(in));
StringBuffer sb = new StringBuffer();
String line = "";
while ((line = bReader.readLine()) != null) {
sb.append(line + " ");
String data = sb.toString();
// System.out.println(data);
PSS = getPSS(data);
if (PSS == null) {
continue;
}
Native = getNative(data);
if (Native == null) {
continue;
}
Dalvik