2015-10-26 76 views
0

我想在我的測試應用程序(棒棒糖)中使用ACRA在Android Studio中獲取基本報告。Android 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); 
         } 
        } 
    

(順便說一句,抱歉代碼以上格式化,但StackOverflow的拒絕適當的格式化它由於某種原因)

這是基於在github上提供ACRA文檔https://github.com/ACRA/acra/wiki/BasicSetup

  • 加入應用程序的名稱和INTERNET權限AndroidManifest

    <!-- 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> 
    

  • 我的主要活動只有一個按鈕,點擊後,就會當它試圖通過零

    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); 
          } 
         }); 
        } 
    } 
    
  • 我期待看到一些形式的通知和某種做到分工崩潰的應用程序報告生成,但我沒有得到任何。我的應用程序在嘗試除零的地方崩潰。

    我不知道我做錯了什麼。

    感謝,

    回答

    1

    類型的通知,你應該選擇爲

    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

    +0

    所以,這將讓彈出對話框,它可以讓我輸入註釋。但它在哪裏發送?我在哪裏看到它?謝謝 – pixel

    +1

    是的,你會得到對話框。它會被髮送到「formUri」指向的任何地方。在上面的代碼中是沒有的。你應該把它指向你的崩潰服務器。 – William

    +0

    @William你會介意推薦一些我可以使用的好的免費崩潰服務器嗎?謝謝 – pixel