10

我正在尝试编写一个读取我设备上所有日志的应用程序。我有一个客户端/服务架构,我看到来自客户端和服务进程的日志消息,但我没有看到来自手机上任何其他应用程序的任何消息(我确实看到使用桌面 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
}
4

3 回答 3

12

在 Android 4.1+ 上,您只能访问由您的进程记录的日志消息,除非您拥有该READ_LOGS权限。该权限要求您的应用使用与设备固件签名相同的签名密钥进行签名,或者您的应用安装在系统分区上。

于 2013-04-25T19:15:14.730 回答
2

要以编程方式从其他应用程序读取日志,您需要在所有 apk 的清单文件中分配相同的 android:sharedUserId。

于 2013-12-15T19:12:28.673 回答
0

还有另一种方法可以在没有 root 的情况下访问所有应用程序的所有日志。它需要启用远程调试。看看开源的无根 Logcat 应用程序

于 2016-07-05T02:51:26.407 回答