1

在我的android测试项目中,我只是阅读了logcat使用adb command

喜欢,

public StringBuilder log=new StringBuilder();
    public String line="";
    public String temp="";

public void testSolo() throws Exception {

             String baseCommand = "logcat -v time";
            baseCommand += " ActivityManager:I "; // Info for my app
            baseCommand += " *:S "; // Silence others

            try {
                  Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);
                  BufferedReader bufferedReader = new BufferedReader(
                   new InputStreamReader(logReaderProcess.getInputStream()));

                   while ((line =bufferedReader.readLine()) != null) {
                            log.append(line); // here readLine() returns null
                          }

            }
            catch (IOException e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                    }

 }

但是,在这里string line我总是得到空值

而同样的事情总是在 android 中运行activity's onCreate()。我不明白为什么会这样?

同样的事情在活动类中运行,而不是在 android 测试项目中。

我还在测试项目的 文件READ_LOGS 中 添加了 use -permission 。WRITE_EXTERNAL_STORAGEmanifest.xml

有没有人知道它是如何工作的或发生了什么?

提前致谢。

4

2 回答 2

0

尝试添加

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

到你的清单。

于 2012-05-18T19:03:47.990 回答
-1
String []baseCommand = new String[]{"logcat", "-v","time"}; 
Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);

试试这个

于 2011-10-07T06:21:53.137 回答