Android ACRA 报告

Android ACRA Reporting

我正在尝试在我的测试应用程序 (Lollipop) 的 Android Studio 中使用 ACRA 获取基本报告。

到目前为止,我已经实现了以下内容:

  1. 在 gradle

    中添加了依赖项
    compile 'ch.acra:acra:4.6.2'
    
  2. 添加了扩展应用程序的 MyApplication 并向其添加了 ReportsCrashes 注释:

    @ReportsCrashes(
    
      resNotifTickerText = R.string.crash_notification_ticker_text,
    
      resNotifTitle = R.string.crash_notification_title,
    
      resNotifText = R.string.crash_notification_text,
    
      resNotifIcon = R.mipmap.error );
    
     public class MyApplication extends Application {
    
            private static final String TAG = MyApplication.class.getSimpleName();
    
             @Override
             public void onCreate(){
                 super.onCreate();
    
                 ACRA.init(this);
             }
         }
    

(顺便说一句,对上面的代码格式化感到抱歉,但 Whosebug 出于某种原因拒绝正确格式化它)

这是基于 github https://github.com/ACRA/acra/wiki/BasicSetup

中提供的 ACRA 文档
  1. 在 AndroidManifest

    中添加了应用程序名称和 INTERNET 权限

    <!-- add INTERNET permission -->
    <uses-permission android:name="android.permission.INTERNET" />
    
    <!-- add application name -->
    <application
        android:name="MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    

  2. 我的主 activity 只有一个按钮,单击时,它会在尝试除以零时使应用程序崩溃

     public class MainActivity extends AppCompatActivity {
         public final static String TAG = MainActivity.class.getSimpleName();
    
         private Button btnError;
    
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);
    
             btnError = (Button) findViewById(R.id.btnError);
             btnError.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
                     Toast.makeText(getApplicationContext(), getString(R.string.toast_app_crash), Toast.LENGTH_SHORT).show();
    
                     Runnable r = new Runnable() {
                         @Override
                         public void run() {
                             // this will crash your app throwing Arithmetic Exception
                             int number = 7 / 0;
                         }
                     };
    
                     Handler h = new Handler();
                     h.postDelayed(r, 2000);
                 }
             });
         }
     }
    

我期待看到生成某种通知和某种报告,但我没有得到。我的应用程序只是在尝试除以零的地方崩溃。

我不确定我做错了什么。

谢谢,

您应该 select 作为

的通知类型
 mode = ReportingInteractionMode.TOAST,
   //Available : Dialog,Notification,Toast and Silent
    resToastText = R.string.crash_text_toast

这是我在我的应用程序中使用的示例报告参数。

    @ReportsCrashes(
    formUri="",
formUriBasicAuthLogin = "CloundantAuthLogin",
formUriBasicAuthPassword = "CloundantAuthKeyPassword",
    reportType = org.acra.sender.HttpSender.Type.JSON,
    httpMethod = org.acra.sender.HttpSender.Method.PUT,
    customReportContent = { ReportField.APP_VERSION_NAME, ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL,ReportField.DEVICE_FEATURES,
    ReportField.USER_APP_START_DATE,ReportField.USER_CRASH_DATE,ReportField.TOTAL_MEM_SIZE,ReportField.USER_COMMENT,
        ReportField.THREAD_DETAILS, ReportField.STACK_TRACE }, 
    mode = ReportingInteractionMode.DIALOG,
    includeDropBoxSystemTags  = true,
    resToastText = R.string.crash_toast_text, // optional, displayed as soon as the crash occurs, before collecting data which can take a few seconds
    resDialogText = R.string.crash_dialog_text,
    resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning sign
    resDialogTitle = R.string.crash_dialog_title, // optional. default is your application name
    resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when defined, adds a user text field input with this text resource as a label
    resDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.
    )

使用的库:acra-4.6.2

迄今为止最好的教程在这里:http://www.toptal.com/android/automated-android-crash-reports-with-acra-and-cloudant