码迷,mamicode.com
首页 > 移动开发 > 详细

Android下读取logcat的信息

时间:2015-04-28 13:44:01      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

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

private static String getLogcatInfo(){
        String strLogcatInfo = "";        
        try{
            ArrayList<String> commandLine = new ArrayList<String>();
            commandLine.add( "logcat");   
            commandLine.add( "-d"); 
            
            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";
            }
        }catch(IOException e){
        }catch(Exception ex){
        }        
        return strLogcatInfo;
    }

 

Android下读取logcat的信息

标签:

原文地址:http://www.cnblogs.com/Martin_Q/p/4462438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!