0

Is it possible to read LogCat messages for all processes? (like in android studio when we choose 'No Filter' option)

When I execute this:

    File filename = new File(Environment.getExternalStorageDirectory() + "/mylog.txt");
    if (filename.exists()) {
        filename.delete();
    }

    String cmd = "logcat -f " + filename.getAbsolutePath();
    Runtime.getRuntime().exec(cmd);

it only writes logs connected to my app.

Lau
  • 1,804
  • 1
  • 23
  • 49

1 Answers1

0

From android version 4.1+ you cannot read logcat of other application anymore. See this for reference.

To read logs of other application for version lower than 4.1

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);
    }
}

You need to give <uses-permission android:name="android.permission.READ_LOGS" /> permission.

Reference

To get clear idea, you can refer this

Community
  • 1
  • 1
Ravi
  • 34,851
  • 21
  • 122
  • 183