2014-09-29 49 views
0

如何實現acra錯誤報告的活動或別的東西?我知道它必須在擴展應用程序的類上,但是可以將acra添加到活動中嗎?如何實施acra活動?

我收到以下錯誤

不能轉換到android.app.application

這是我的代碼添加

@ReportsCrashes(
    formUri = "http://test.com/cekErr", 

      formUriBasicAuthLogin = "GENERATED_USERNAME_WITH_WRITE_PERMISSIONS", 
      formUriBasicAuthPassword = "GENERATED_PASSWORD", 
    formKey = "", 
    customReportContent = { 
      ReportField.APP_VERSION_CODE, 
      ReportField.APP_VERSION_NAME, 
      ReportField.ANDROID_VERSION, 
      ReportField.PACKAGE_NAME, 
      ReportField.REPORT_ID, 
      ReportField.BUILD, 
      ReportField.STACK_TRACE 
    }, 
    resToastText = R.string.app_name 
) 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ACRAConfiguration config = ACRA.getNewDefaultConfig(this.getApplication()); 
    config.setResToastText(R.string.app_name); 
    ACRA.setConfig(config); 

    ACRA.init(this.getApplication()); 
    Map<ReportField, String> mapping = new HashMap<ReportField, String>(); 
    mapping.put(ReportField.APP_VERSION_CODE, "myAppVerCode"); 
    mapping.put(ReportField.APP_VERSION_NAME, "myAppVerName"); 
    mapping.put(ReportField.LOGCAT, "myAppErr"); 
    // ... 
    mapping.put(ReportField.USER_EMAIL, "userEmail"); 
    // remove any default report sender 
    ACRA.getErrorReporter().removeAllReportSenders(); 
    // create your own instance with your specific mapping 
    ACRA.getErrorReporter().addReportSender(
      new HttpPostSender 
      ("http://test.com/cekErr" 
        , mapping)); 
} 
+0

這個[鏈接]請不要忘記在AndroidManifest.xml文件中指定這個[link](http://www.toptal.com/android/automated-android-crash-reports-with-acra-and-cloudant) – ashutiwari4 2014-09-29 06:12:19

回答

1

號ACRA到您的整個應用程序。 如果您還沒有一個Application類,只需創建一個從Application擴展的類。

+1

作爲你的應用程序類。 – EpicPandaForce 2014-09-29 13:40:12

1

您不需要將acra添加到需要配置到應用程序類級別的活動中。

MyApplication.java

import org.acra.*; 
import org.acra.annotation.*; 

@ReportsCrashes(
    formKey = "", // This is required for backward compatibility but not used 
    formUri = "http://www.backendofyourchoice.com/reportpath" 
) 
public class MyApplication extends Application { 
    @Override 
    public void onCreate() { 
     super.onCreate(); 

     // The following line triggers the initialization of ACRA 
     ACRA.init(this); 
    } 
} 

應用

<application android:icon="@drawable/icon" android:label="@string/app_name"     android:name="MyApplication"> 

Permition

<uses-permission android:name="android.permission.INTERNET"></uses-permission> 

遵循這個基本setup

0

正如同事已經呈現T舊的你,ACRA被添加到整個應用程序中。因此,將ACRA添加到您的應用程序中,但僅在所需的活動中使用它。