如何实施关于活动或其他内容的错误报告?我知道必须在扩展应用程序的类上,但是有可能在活动中添加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));
}
最佳答案
您无需将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">
渗透
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
遵循此基本setup