在错误情况下接收我的应用程序的应用程序日志的最佳做法是什么?

时间:2013-01-17 14:13:49

标签: android

我想在我的应用中启用一些错误报告,因为我正在寻找一种适用于高于api等级8的设备的方式

我当前的实现在Android 4.1.1设备上不起作用,当用户按下错误报告按钮时没有动作。在设备2.2,2.3和4.0.4上,它显示了不同的电子邮件选项。

我的代码中的操作方法如下所示

public void startSendErrorAction(View view) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType( "text/plain" );
    intent.putExtra( Intent.EXTRA_EMAIL, new String[]{"my@email.de" });
    intent.putExtra( Intent.EXTRA_SUBJECT, "PDiXAttach LogReport from " + DateTime.now());
    intent.putExtra( Intent.EXTRA_TEXT, getLogContent() );

    startActivity(intent);        

}

getLogContent方法使用logcat -d选项检索应用程序日志条目。但它目前无法在设备上运行

Hersteller: samsung
Modell: GT-N7100
Marke: samsung
Version: 4.1.1 (REL)

这里是getLogContent-Method

public String getLogContent() {
    StringBuffer sb = new StringBuffer();
    String separator = System.getProperty( "line.separator" );
    Process process;
    try {
        process = Runtime.getRuntime().exec( "logcat -d" );
        BufferedReader bufferedReader = new BufferedReader(
                                                            new InputStreamReader( process.getInputStream() ) );
        String line;
        while( (line = bufferedReader.readLine()) != null ) {
            sb.append( line );
            sb.append( separator );
        }
        Log.d( TAG, "retrieve log content size is " + sb.length() );

    }
    catch( IOException e ) {
        Log.e( TAG, "error while retrieving logfile of application" + e.getMessage() );
    }

    return sb.toString();

}

有人知道可能是什么原因。

2 个答案:

答案 0 :(得分:3)

ACRA可以很好地完成你想要的任务,并且适用于我使用它时所困扰的所有Android版本。它提供了比Google Play报告更多的详细信息,并且可以非常有助于远程追踪错误。

答案 1 :(得分:0)

您还可以使用Alogcat 进行运行时崩溃。

相关问题