2010-08-25 58 views
2

有谁知道如何使用Java以编程方式获取android设备系统日志?这与Dalvik调试监视器下面板上提供的类似。如何从Java程序获取Android系统日志

在此先感谢。

+0

你想从你的Android应用程序内部或外部此访问日志的输出?您是使用模拟器还是设备? – naikus 2010-08-25 04:50:38

回答

2

未经测试与“亚行外壳的logcat”,但我用这个从通过ADB得到其他的东西:

public static String[] getAdbLogCat() { 

    try { 
     Process p = Runtime.getRuntime().exec("/path/to/adb shell logcat"); 
     InputStream is = p.getInputStream(); 
     InputStreamReader isr = new InputStreamReader(is); 
     BufferedReader br = new BufferedReader(isr); 

     final StringBuffer output = new StringBuffer(); 
     String line; 
     ArrayList<String> arrList = new ArrayList<String>(); 
     while ((line = br.readLine()) != null) { 
      System.out.println(line); 
     } 
     return (String[])arrList.toArray(new String[0]); 
    } catch (IOException e) { 
     System.err.println(e); 
     e.printStackTrace(); 
     return new String[]{}; 
    } 
} 
+0

感谢Mathias,那正是我需要的:)你摇滚! – phillyville 2010-08-25 18:27:21

+0

只是为了获得快速信息,'adb shell logcat'工作得很好,'adb logcat'也是如此:) – phillyville 2010-08-25 22:47:51

相关问题