Android侦听/检测日志中的条目

时间:2010-08-22 23:09:12

标签: android logging broadcastreceiver

是否可以收听日志条目? 即是否有附加日志条目的广播意图?

2 个答案:

答案 0 :(得分:2)

没有意图。

使用以下代码:

try
    {
        Process mLogcatProc = null;
        BufferedReader reader = null;
        mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});

        reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));

        String line;
        final StringBuilder log = new StringBuilder();
        String separator = System.getProperty("line.separator"); 

        while ((line = reader.readLine()) != null)
        {
            log.append(line);
            log.append(separator);
        }
        String w = log.toString();
        Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();
    }
    catch (Exception e) 
    {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }

你将需要它的许可:

android.permission.READ_LOGS

答案 1 :(得分:1)

如果“日志”是指LogCat,则不会有广播Intents用于向LogCat添加条目。