问题描述
我有一个服务,该服务想从服务启动时从logcat读取数据(即在服务启动之前丢弃logcat数据),实时监视logcat数据,过滤logcat以仅显示"ActivityManager"和参考日志.
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.
然后,我想根据过滤后的logcat数据执行某些操作.我尝试了以下操作,但不起作用:
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?
推荐答案
确定,结果我错过了logcat中的-s参数,该参数过滤了logcat输出.
OK, turns out I missed out the -s parameter in logcat, which filters the logcat output.
这篇关于如何以编程方式实时读取logcat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!