如何在活动或其他方面实施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 :(得分:1)
没有。 ACRA已添加到您的整个应用程序中。 如果您还没有Application类,只需创建一个从Application扩展的类。
答案 1 :(得分: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
答案 2 :(得分:0)
正如同事已经告诉你的那样,ACRA被添加到整个应用程序中。因此,请将ACRA添加到您的应用中,但仅在所需的活动中使用它。