与我的应用程序内的logcat的输出错误 [英] Wrong output with logcat inside my application

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

问题描述

我正在开发一个多标签的应用。在选项卡之一,我想显示logcat的,但我有很多的问题,正确地运行它。

I'm developing a multi-tab application. In one of the tab I want to show the logcat but I have a lot of problem running it correctly.

现在,我使用下面的命令,但我没有得到我的TextView什么。

Right now I'm using the following command but I don't get anything in my TextView. :

Process process = Runtime.getRuntime().exec("/system/bin/logcat -s com.vittorio:I");

但是当我运行相同的命令到终端它的工作原理flawlessy。

But when I run the same command into Terminal it works flawlessy.

我也tryed这另一个命令:

I've also tryed this other command :

Process process = Runtime.getRuntime().exec("/system/bin/logcat *:I");

但由于某种原因它也打印调试级别的消息...

but for some reason it prints also Debug level messages ...

编辑(1):

我通过增加一个高层次的过滤器(JAVA)整​​个日志绕过这个问题..所以我只在我的TextView打印我需要什么。这是一个非常肮脏的解决方案,但现在是我设法来与唯一的一个。

I've by-passed the problem by adding an high-level filter (java) to the whole log.. so I only print in my textview what I need. It's a very dirty solution but for now is the only one I managed to come with.

我想指出的是,I'me我的手机体验不同的行为:

I would like to point out that I'me experiencing different behaviours on my phones :


  • Galaxy S的加号(扎根):我可以看到日志

  • 银河Y(扎根):无日志

  • 的Nexus One(不是根):无日志

编辑(2) - 解决(NEED根植电话)

有些挣扎后,我设法解决我的问题。通过init.rc系统文件其实导航我看到权限的/ dev /日志/主和/ dev /日志/系统中设置好的620 ..这就是为什么我不能打开日志上的我的一些手机。所以我也根源于我的Nexus One和增加这个命令到我的活动调用logcat的命令之前:

After some struggling I managed to solve my problem. Actually navigating through the init.rc system file I saw that the permissions for /dev/log/main and /dev/log/system where setted to 620.. that's why I couldn't open the log on some of my phones. So I rooted also my Nexus One and added this commands into my activity before calling the logcat command :

Process process_su = Runtime.getRuntime().exec("su");
Process process_ch = Runtime.getRuntime().exec("chmod 777 /dev/log/main");

完成! :D

希望这个信息将帮助任何人谁都会面对我同样的问题。

Hope this info will help anyone who will face my same issue.

推荐答案

您必须使用此权限:

<uses-permission android:name="android.permission.READ_LOGS" />

然后就可以使用代码片段,我发现

and then you can use that snippet i found

    try {
      Process process = Runtime.getRuntime().exec("logcat -v");

      BufferedReader bufferedReader = new BufferedReader(
      new InputStreamReader(process.getInputStream()));

      StringBuilder logString=new StringBuilder();
      String line;

      while ((line = bufferedReader.readLine()) != null) {
        logString.append(line);
      }

      TextView tv = (TextView)findViewById(R.id.logTextView);
      tv.setText(logString.toString());

    } catch (IOException e) {

    }

我没有尝试,但它似乎是正确的。

I didn't try it but it seems correct

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

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