有谁知道如何使用 Java 以编程方式获取 android 设备系统日志?这类似于 Dalvik 调试监视器下方面板上提供的内容。
提前致谢。
最佳答案
未经“adb shell logcat”测试,但我已使用它通过 adb 获取其他内容:
public static String[] getAdbLogCat() {
try {
Process p = Runtime.getRuntime().exec("/path/to/adb shell logcat");
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
final StringBuffer output = new StringBuffer();
String line;
ArrayList<String> arrList = new ArrayList<String>();
while ((line = br.readLine()) != null) {
System.out.println(line);
}
return (String[])arrList.toArray(new String[0]);
} catch (IOException e) {
System.err.println(e);
e.printStackTrace();
return new String[]{};
}
}
关于java - 如何从Java程序获取android系统日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3561958/