在SD文件保存应用程序事件(logcat中) [英] Save app event (logcat) in file on sd

查看:118
本文介绍了在SD文件保存应用程序事件(logcat中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要救我的应用程序的logcat事件SD卡上的文本文件。
在我和我的朋友我的设备应用程序惊人的正常工作,但其他的对我的应用程序错误。
例如,他们说,在应用程序的警报在错误的时间,但我没有看到这个错误在我和我的朋友的设备。
因为这个问题和其他问题,我想救logcat的有关我的应用程序,atomatically的所有事件。所以他们的日志文件发送给我解决问题。
我怎样才能做到这一点?
谢谢
对不起,我的英语不好

I want to save my app logcat events in a text file on sd card. my alarming app work properly in my and my friends devices, but other have error on my app. for example they say alarms in app are in wrong time, but i dont see this error in my and my friends devices. Because of this issue and other issues, i want save all events logcat related my app, atomatically. so they send log file to me to solve issues. how can i do this? thanks sorry for my bad english

推荐答案

您可以通过以下获得logcat的:

You can get logcat via the following:

static final int BUFFER_SIZE = 1024;

public String getLogCat() {
    String[] logcatArgs = new String[] {"logcat", "-v", "time"};

    Process logcatProc = null;
    try {
        logcatProc = Runtime.getRuntime().exec(logcatArgs);
    }
    catch (IOException e) {
        return null;
    }

    BufferedReader reader = null;
    String response = null;
    try {
        String separator = System.getProperty("line.separator");
        StringBuilder sb = new StringBuilder();
        reader = new BufferedReader(new InputStreamReader(logcatProc.getInputStream()), BUFFER_SIZE);
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
            sb.append(separator);
        }
        response = sb.toString();
    }
    catch (IOException e) {
    }
    finally {
        if (reader != null) {
            try {
                reader.close();
            }
            catch (IOException e) {}
        }
    }

    return response;
}

您可以保存此字符串到SD卡。

You can then save this String to the sdcard.

这篇关于在SD文件保存应用程序事件(logcat中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆