如何逐行编程地读取Logcat

时间:2012-11-10 12:27:37

标签: android logcat

我想逐行使用我的应用程序本身阅读我的Log cat。这是我把它放在下面的代码

  try {
        Process process = Runtime.getRuntime().exec("logcat -v time");//logcat -v time//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);
        System.out.println("logas = "+log);
        tv.setText(log.toString());

      } catch (IOException e) {
      }

所以基本上我想调整此代码来读取log cat,直到使用停止它。所以我应该开始使用asyncTask还是有其他解决方案?

0 个答案:

没有答案