如何获取其他应用程序的日志? [英] How to get logs of other apps?

查看:149
本文介绍了如何获取其他应用程序的日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从其他应用程序中读取日志并进行过滤,以便在记录特定关键字时,我的应用程序将执行特定任务.

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.

推荐答案

如果设备已植根,则只能读取所有应用程序的日志.

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

如果您想读取已根设备的日志,那么应该可以为您提供帮助.但是,您必须将targetSdk设置为16.

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

这篇关于如何获取其他应用程序的日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆