6

I want to read logs from other apps and filter them so when a certain keyword is being logged, my application will perform a certain task.

I found several methods of reading logs, but from my testing I could only get my application logs.

This is the method I originally tried to use

try {
  Process process = Runtime.getRuntime().exec("logcat -d");
  BufferedReader bufferedReader = new BufferedReader(
  new InputStreamReader(process.getInputStream()));

  StringBuilder log=new StringBuilder();
  String line = "";
  while ((line = bufferedReader.readLine()) != null) {
    log.append(line);
  }
  TextView tv = (TextView)findViewById(R.id.textView1);
  tv.setText(log.toString());
  } 
catch (IOException e) {}

But it seems like it only reads the logs of my app.

Rosenpin
  • 862
  • 2
  • 11
  • 40

1 Answers1

3

You can only read the logs of all apps if the device is rooted.

If you want to read logs of rooted devices, then this should help you. However, you will have to set the targetSdk to 16.

Community
  • 1
  • 1
Harsh Pandey
  • 831
  • 7
  • 12
  • Do you have the code for that? This is what I'm looking for. – Rosenpin Jul 15 '16 at 01:54
  • I'm not sure if you fully understand what it means to root a device. Please read [this](http://www.digitaltrends.com/mobile/how-to-root-android/). – Harsh Pandey Jul 15 '16 at 01:56
  • I know very well what a rooted device is.. It's not a problem for me to make my app root only. I'm just asking your code to read system logs on rooted devices. – Rosenpin Jul 15 '16 at 01:57
  • Sorry for misunderstanding you back there. Please check edit @Rosenpin. – Harsh Pandey Jul 15 '16 at 02:04