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[]{};
}
}
也可以用 'adb logcat'
logcat
最新推荐文章于 2020-04-08 10:46:07 发布
本文介绍了一种通过Java代码调用ADB命令获取Logcat日志的方法。该方法使用Runtime类执行外部命令,通过流读取Logcat输出,并将每条日志存储到ArrayList中返回。适用于Android应用开发者进行调试。
1348

被折叠的 条评论
为什么被折叠?



