Android下读取logcat的信息


有时我们需要在程序执行进程中遇到一些异常,需要收集一logcat的信息,android下就可以使用以下方法获取:

private static String getLogcatInfo(){
        String strLogcatInfo = "";        
        try{
            ArrayList<String> commandLine = new ArrayList<String>();
            commandLine.add("logcat");   
            commandLine.add( "-d"); 
commandLine.add("*:E"); // 过滤所有的错误信息
ArrayList
<String> clearLog = new ArrayList<String>(); //设置命令 logcat -c 清除日志 clearLog.add("logcat"); clearLog.add("-c"); Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[commandLine.size()])); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); String line = null; while ((line = bufferedReader.readLine()) != null) { Runtime.getRuntime().exec(clearLog.toArray(new String[clearLog.size()])); strLogcatInfo = strLogcatInfo + line + "\n"; }

bufferedReader.close(); }
  
catch(Exception ex)
{
process.destroy(); }
return strLogcatInfo; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM