Android: read the logcat programmatically
This is how you can read the logcat:
Process logcat;
final StringBuilder log = new StringBuilder();
try {
logcat = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});
BufferedReader br = new BufferedReader(new InputStreamReader(logcat.getInputStream()),4*1024);
String line;
String separator = System.getProperty("line.separator");
while ((line = br.readLine()) != null) {
log.append(line);
log.append(separator);
}
} catch (Exception e) {
e.printStackTrace();
}
And this is how you can clear it:
try {
Runtime.getRuntime().exec(new String[]{"logcat", "-c"});
} catch (Exception e1) {
e1.printStackTrace();
}
Written by Daniele Rigo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#