How I start a process to run logcat on Android?
- by tangjie
I want to read Android system level log file.So I use the following code:
Process mLogcatProc = null;
BufferedReader reader = null;
try {
mLogcatProc = Runtime.getRuntime().exec(
new String[] { "logcat", "-d",
"AndroidRuntime:E [Your Log Tag Here]:V *:S" });
reader = new BufferedReader(new InputStreamReader(mLogcatProc
.getInputStream()));
String line;
final StringBuilder log = new StringBuilder();
String separator = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
log.append(line);
log.append(separator);
}
}
catch (IOException e) {}
finally {
if (reader != null)
try {
reader.close();
} catch (IOException e) {}
}
I also used in AndroidManifest.xml.
But I can't read any line. The StringBuilder log is empty. And the method mLogcatProc.waitFor return 0.
So how can I read the log ?