1

我想显示应用程序日志。在终端上我使用了这个命令: adb logcat -s brief *:V|grep "pid" 它显示我的应用程序日志。

pid 表示在 logcat 表中显示的应用程序 pid。

  public static String logProc()
{
     String value = "";
     try
     {
         String cmd[] = {"logcat","-s","brief","*:V","|","grep",
                 android.os.Process.myPid()+""};
         Process p = Runtime.getRuntime().exec(cmd,null, null);
         BufferedReader reader = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));
         String line = reader.readLine();

         while (line != null)
         {
             value += line + "\n";
             line = reader.readLine();
         }
         p.waitFor();
     }
     catch (IOException e1)
     {
         e1.printStackTrace();
     } 
     catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return value;
}
4

0 回答 0