Android 监听/检测日志条目

标签 android logging broadcastreceiver

是否可以监听日志条目? 即附加日志条目时是否有广播 Intent ?

最佳答案

没有 Intent 。

使用下面的代码:

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

关于Android 监听/检测日志条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3543846/

相关文章:

Android - 兼容性库 v4 异常 (EdgeEffect) java.lang.NoClassDefFoundError : > android. widget.EdgeEffect

java - 无法解析 : firebase-database-15. 0.0(并将数据库保留在应用程序中)

android - 检查 INTENT 互联网连接

C#:ILogger 与静态日志实例

Python 日志记录数据报处理程序

Android - 尝试在启动时测试服务(java.lang.SecurityException : Permission Denial)

android - 广播 INSTALL_REFERRER Intent 问题

android - 如何显示带有扩展 BaseActivity 的数据绑定(bind)的 childActivity?

android - 是否有 adb/shell 命令来列出 android 通知栏上的项目?

mysql - 单表动态返回多个平均值的SQL语句是什么