Read logcat continuously in Android app -
i'm trying read continuously - means:
if, example, have process every few second write logcat, want app listen on logcat, once new line added - catch , show on screen
i have 1 activity every second write counter log:
runnable r = new runnable() { @override public void run() { i++; log.d("bbb", "i= " + i); mhandler.postdelayed(this, 1000); } };
i have service trying "listen" on "logcat -s bbb", once listener started - app stuck (looks app entered endless loop) , after few seconds got message app must closed.
the listener code is: (the message "start read line" printed , that's it...)
public static void parse() { runtime rt = runtime.getruntime(); process process = null; try { process = rt.exec("su"); dataoutputstream os = new dataoutputstream(process.getoutputstream()); os.writebytes("logcat -s bbb"); os.flush(); } catch (ioexception e1) { e1.printstacktrace(); } bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(process.getinputstream())); string line; try { log.d("aaa","start read line"); while ((line = bufferedreader.readline()) != null) { log.d("aaa", "line = " + line); } log.d("aaa", "finish"); } catch (ioexception e) { e.printstacktrace(); } }
the service call function parse() once.
someone have idea wrong?
*** edit: found problem - command "logcat -s bbb" should execute rt (process = rt.exec("logcat -s bbb")), , don't need dataoutputstream) thanks!
Comments
Post a Comment