I have a service that would like to read data from logcat, from the start of the service (i.e. discarding logcat data prior to service start), monitoring the logcat data in real time, filtering the logcat to only show tags of "ActivityManager" and informational logs.
I would then like to perform certain actions based on the filtered logcat data. I tried the following, but it doesn't work:
Runtime.getRuntime().exec("logcat -c"); // flush the logcat first
Process process = Runtime.getRuntime().exec("logcat ActivityManager:I"); // filters logcat to only "ActivityManager:I" logs
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line = "";
Log.d(TAG, "Reading filtered logcat");
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}
Does anyone know where I'm going wrong?
OK, turns out I missed out the -s parameter in logcat, which filters the logcat output.