如何实现活动或其他方面的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));
}
您不需要向应用程序类级别添加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>
按照这个基本设置
否。ACRA会添加到您的整个应用程序中。如果您还没有Application类,只需创建一个从Application扩展而来的类。
正如同事们已经告诉您的,ACRA被添加到整个应用程序中。因此,将ACRA添加到您的应用程序中,但只能在所需的"活动"中使用。