开发者

How can I extract events log from Android application?

I was able to extract main logs from Android application by using the following code:

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();
        }

However, when I try to use the same method to extract event logs, it does not work. I have no idea what the problem is, but when I change LOGCAT_CMD to the following and run the application, ireader.read() returns -1 right away and fini开发者_运维百科shes.

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

Could somebody please help me?


Check out this code. In particular look at collectAndSendLog() in SendLogActivity.java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜