我发现Logcat 的优秀功能。它可以通过使用简单的命令参数“-f”将输出重定向到自己的文件。要使用它,您可以在应用程序 aLogcat 中编写 Logcat 包装器。显然这是我做的:)
为了在 android 上使用 logcat 我写了这段代码:
Process proc = null;
try {
proc = Runtime.getRuntime().exec(new String[] { "logcat", <!parametes_here!> });
mReader = new BufferedReader(new InputStreamReader(proc.getInputStream()), 1024);
String line;
while ((line = mReader.readLine()) != null) {
if (line.length() == 0) {
continue;
}
mHandler.sendMessage(mHandler.obtainMessage(Logcat.MSG_READ_LINE, line));
}
} catch (IOException e) {
Log.e(TAG, "Cannot start process", e);
} finally {
if (mReader != null)
try {
mReader.close();
} catch (IOException e) {
Log.e(TAG, "Cannot close stream", e);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2241 次 |
| 最近记录: |