phi*_*lle 4 java logging android
有谁知道如何使用 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[]{};
}
}
Run Code Online (Sandbox Code Playgroud)