zoukankan      html  css  js  c++  java
  • 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 + " "; }

    bufferedReader.close(); }
      
    catch(Exception ex)
    {
    process.destroy(); }
    return strLogcatInfo; }
  • 相关阅读:
    Vulnhub_DC4 记录
    文件上传(解析)漏洞
    开源情报搜集
    Vulnhub_DC3 记录
    “恶意”利用IPC$
    Vulnhub_DC2 记录
    Vulnhub_DC1 记录
    合天网安实验室 渗透测试项目二
    合天网安实验室 渗透测试项目一
    编程如写作
  • 原文地址:https://www.cnblogs.com/Martin_Q/p/4462438.html
Copyright © 2011-2022 走看看