How to get logs of other apps?

China☆狼群 提交于 2019-12-10 13:25:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/38386688/how-to-get-logs-of-other-apps

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