【问题标题】:How can I extract events log from Android application?如何从 Android 应用程序中提取事件日志?
【发布时间】:2011-07-27 05:01:23
【问题描述】:

我能够使用以下代码从 Android 应用程序中提取主日志:

String[] LOGCAT_CMD = new String[] {
    "logcat",
    "-d",
    "MyApplication:E",
    "*:S"};
    Process logcatProc = null;

    try {
        logcatProc = Runtime.getRuntime().exec(LOGCAT_CMD);
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
String lineSeparator = System.getProperty("line.separator");

    StringBuilder strOutput = new StringBuilder();
    try {
        InputStream ireader = logcatProc.getInputStream();
        int temp;
        while ( (temp = ireader.read()) != -1 ){
            while ( temp !=  64 ){
                strOutput.append( (char) temp);
                temp = ireader.read();
            }
            strOutput.append(lineSeparator);
            line = strOutput.toString();
            writeLine(line);
            strOutput = new StringBuilder();
        }

但是,当我尝试使用相同的方法来提取事件日志时,它不起作用。我不知道问题是什么,但是当我将 LOGCAT_CMD 更改为以下并运行应用程序时,ireader.read() 立即返回 -1 并完成。

String[] LOGCAT_CMD = new String[] {
            "logcat",
            "-b",
            "events",
            "-d",
            "[1]:I",
            "*:S"
            };

有人可以帮帮我吗?

【问题讨论】:

    标签: android process event-log logcat android-logcat


    【解决方案1】:

    查看this code。特别注意SendLogActivity.java中的collectAndSendLog()。

    【讨论】:

    • 我不认为这是我需要的。当我将 LOGCAT_CMD 设置为“logcat -b main -d”时,它工作正常。但是,当我尝试“logcat -b events -d”或“logcat -b radio -d”时,InputStream ireader 立即返回 -1 并结束。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多