以编程方式应用 logcat 过滤器
我需要以编程方式使用过滤器转储 logcat。我应用了 adb logcat -s "TAGNAME" 但应用程序只是“挂起”。有一个类似的线程,但没有解决方案:读取过滤的日志猫(以编程方式)?
try {
Process process = Runtime.getRuntime().exec("logcat -s XXX");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append(FragmentLog.LINE_SEPARATOR);
}
((TextView) tv).setText(log.toString());
} catch (IOException e) {
((TextView) tv).setText(R.string.default_blank);
}
I need to dump logcat with filter programmatically. I applied adb logcat -s "TAGNAME" but the app just "hung". there is a similar thread but there is no solution: Read filtered log cat(Programmatically)?
try {
Process process = Runtime.getRuntime().exec("logcat -s XXX");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append(FragmentLog.LINE_SEPARATOR);
}
((TextView) tv).setText(log.toString());
} catch (IOException e) {
((TextView) tv).setText(R.string.default_blank);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用另一种方式来让我的应用程序运行。这是代码,以防有人想知道。
I am using another way to get my app work. Here is the code, in case anyone wants to know,.
首先,这个命令将流式传输 logcat 并且不会转储它。因此它永远不会停止运行。另外,如果没有内容要报告,BufferedReader 可能正在等待整行输入,因此您会阻塞。
Well first off this command will stream logcat and won't dump it. Hence it will never quit running. Also, if there is no content to report the BufferedReader is probably waiting for a full line to come in, so you are blocking.