How can I get logcat on my device to show logs from all processes

ⅰ亾dé卋堺 提交于 2019-11-30 03:21:31

问题


I'm trying to write an app that reads all logs on my device. I've got a client/service architecture, and I see log messages from both the client and service processes but I don't see any messages from any other applications on the phone (I do see other messages using the desktop logcat).

Do I need root?

Code Snippets

Manifest

<uses-permission android:name="android.permission.READ_LOGS" />

Log Reader

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
}

回答1:


On Android 4.1+, you can only access log messages logged by your process, unless you hold the READ_LOGS permission. That permission requires either that your app be signed by the same signing key that signed the device's firmware, or that your app is installed on the system partition.




回答2:


To read logs from other applications programmatically, you will need to assign the same android:sharedUserId in all apks' manifest files.




回答3:


There is another way to access all logs for all applications without root. It requires enabling remote debugging. Take a look at the open source rootless Logcat app.



来源:https://stackoverflow.com/questions/16222766/how-can-i-get-logcat-on-my-device-to-show-logs-from-all-processes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!