I'm working with my application and ACRA. I want to know some state behavior with my application when crash occur. How it can be done? Is any event listener just before collect report content so i can implement it and put latest custom data?
This is my code so far:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ACRA.init(this);
boolean wifiEnable = CheckWifi();
ACRA.getErrorReporter().putCustomData("wifiEnable", "Wifi Enable " + wifiEnable);
}
...
The code above doesn't meet what I want, custom data wifiEnable
not getting update when report send even on wifiEnable
state change at crash occur.
I try new code something like this and working, but only if report send immediately, for pending report the wifiEnable
variable will replace with new state:
ACRA.init(this);
ACRA.getErrorReporter().setReportSender(new HttpSender(
org.acra.sender.HttpSender.Method.PUT,
org.acra.sender.HttpSender.Type.JSON,
null
) {
@Override
public void send(CrashReportData report) throws ReportSenderException {
boolean wifiEnable = CheckWifi();
report.put(ReportField.CUSTOM_DATA, "wifiEnable=" + "Wifi Enable " + wifiEnable);
super.send(report);
}
});
I try to create ACRA.getErrorReporter().putCustomData()
in every activity onCreate()
but no luck.
Any help would be nice. Thanks.
Thanks for helping me, i was solve my problem and meet what i need, i just change the source src/main/java/org/acra/ErrorReporter.java
from ACRA 4.5.0
This the code that i have done:
private static BeforeReportSendListener mBeforeReportSendListener;
public void setBeforeReportSendListener(BeforeReportSendListener listener) {
mBeforeReportSendListener = listener;
}
public static interface BeforeReportSendListener {
void onBeforeReportSend();
}
Next, add this code in handleException()
method:
if(mBeforeReportSendListener != null) {
mBeforeReportSendListener.onBeforeReportSend();
}
This is show how can i use it:
ACRA.init(this);
ACRA.getErrorReporter().setBeforeReportSendListener(new ErrorReporter.BeforeReportSendListener() {
@Override
public void onBeforeReportSend() {
// Check some state when crash happen
boolean wifiEnable = CheckWifi();
ACRA.getErrorReporter().putCustomData("wifiEnable", "Wifi Enable " + wifiEnable);
// and more...
}
});