如何在Android中读取系统日志文件? [英] How to read system log file in Android?
本文介绍了如何在Android中读取系统日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读系统日志在我的code,产生类似的错误报告。 类似的亚行logcat,但在节目的方式。
I am trying to read system logs in my code to generate something like an error report. Similar to adb logcat, but in a programming way.
我怎样才能做到这一点?
How can I achieve this?
推荐答案
日志收集有其源$ C $ C,适用于谷歌code。他们实际上只需要调用logcat的。在这里看到:<一href="https://$c$c.google.com/p/android-log-collector/source/browse/trunk/src/com/xtralogic/android/logcollector/SendLogActivity.java?r=2"相对=nofollow> Android的日志收集 - SendLogActivity.java
Log Collector has their source code available on Google Code. They actually just call logcat. See here: android-log-collector - SendLogActivity.java
下面是关键的部分:
ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat");//$NON-NLS-1$
commandLine.add("-d");//$NON-NLS-1$
ArrayList<String> arguments = ((params != null) && (params.length > 0)) ? params[0] : null;
if (null != arguments){
commandLine.addAll(arguments);
}
Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null){
log.append(line);
log.append(App.LINE_SEPARATOR);
}
这篇关于如何在Android中读取系统日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文