Sometimes we need to encounter some exceptions in the program execution process, we need to collect a logcat of information, the following methods can be obtained under Android:
Private Staticstring Getlogcatinfo () {string Strlogcatinfo= ""; Try{ArrayList<String> CommandLine =NewArraylist<string>(); Commandline.add ("Logcat"); Commandline.add ("-D"); ArrayList<String> Clearlog =NewArraylist<string> ();//set command logcat-c clear logClearlog.add ("Logcat"); Clearlog.add ("-C"); Process Process= Runtime.getruntime (). EXEC (Commandline.toarray (Newstring[commandline.size ()]); BufferedReader BufferedReader=NewBufferedReader (NewInputStreamReader (Process.getinputstream ())); String Line=NULL; while(line = Bufferedreader.readline ())! =NULL) {runtime.getruntime (). EXEC (Clearlog.toarray (Newstring[clearlog.size ()]); Strlogcatinfo= Strlogcatinfo + line + "\ n"; } }Catch(IOException e) {}Catch(Exception ex) {}returnStrlogcatinfo; }
Read Logcat information under Android