我正在尝试编写一个读取我设备上所有日志的应用程序。我有一个客户端/服务架构,我看到来自客户端和服务进程的日志消息,但我没有看到来自手机上任何其他应用程序的任何消息(我确实看到使用桌面 logcat 的其他消息)。
我需要root吗?
代码片段
显现
<uses-permission android:name="android.permission.READ_LOGS" />
日志阅读器
Runtime.getRuntime().exec("logcat -c").waitFor();
Process process = Runtime.getRuntime().exec("logcat -v long *:*");
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
String nextLine = reader.readLine();
if (!nextLine.contains("LogWatcher-D")) {
Log.w("LogWatcher-D", "See: " + nextLine);
}
// Process line
}