在应用程序读取logcat的编程 [英] Read logcat programmatically within application

查看:159
本文介绍了在应用程序读取logcat的编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读并作出反应在我的应用程序的logcat日志。

I want to read and react to logcat logs within my application.

我发现旁边code:

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

这code确实返回,使得直到应用程序的当前运行的logcat的日志 -

This code indeed returns the logcat logs that made until the current run of the application -

但有可能为在线听logcat的日志?

But is it possible to "online" listen to logcat logs?

推荐答案

您可以继续阅读日志,只是去掉了-d标志,在code以上。

You can keep reading the logs, just by removing the "-d" flag in your code above.

在-d标志指示在LogCat中显示日志内容并退出。如果你删除标志,logcat中不会终止,并保持在发送任何新行添加到它。

The "-d" flag instruct to logcat to show log content and exit. If you remove the flag, logcat will not terminate and keeps sending any new line added to it.

只是有一点,这可能会阻止你的应用程序,如果没有正确的设计。

Just have in mind that this may block your application if not correctly designed.

好运。

这篇关于在应用程序读取logcat的编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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