Step 1: Add the dependency of latest ACRA AAR to your application gradle(build.gradle).
Step 2:
In your application class(the class which extends Application; if not create it) Add a @ReportsCrashes
annotation and override the attachBaseContext()
method.
Step 3: Initialize the ACRA class in your application class
@ReportsCrashes(
formUri = "Your choice of backend",
reportType = REPORT_TYPES(JSON/FORM),
httpMethod = HTTP_METHOD(POST/PUT),
formUriBasicAuthLogin = "AUTH_USERNAME",
formUriBasicAuthPassword = "AUTH_PASSWORD,
customReportContent = {
ReportField.USER_APP_START_DATE,
ReportField.USER_CRASH_DATE,
ReportField.APP_VERSION_CODE,
ReportField.APP_VERSION_NAME,
ReportField.ANDROID_VERSION,
ReportField.DEVICE_ID,
ReportField.BUILD,
ReportField.BRAND,
ReportField.DEVICE_FEATURES,
ReportField.PACKAGE_NAME,
ReportField.REPORT_ID,
ReportField.STACK_TRACE,
},
mode = NOTIFICATION_TYPE(TOAST,DIALOG,NOTIFICATION)
resToastText = R.string.crash_text_toast)
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// Initialization of ACRA
ACRA.init(this);
}
}
Where AUTH_USERNAME and AUTH_PASSWORD are the credentials of your desired backends.
Step 4: Define the Application class in AndroidManifest.xml
<application
android:name=".MyApplication">
<service></service>
<activity></activity>
<receiver></receiver>
</application>
Step 5: Make sure you have internet
permission to receive the report from crashed application
<uses-permission android:name="android.permission.INTERNET"/>
In case if you want to send the silent report to the backend then just use the below method to achieve it.
ACRA.getErrorReporter().handleSilentException(e);