Yusuf Rifai
Yusuf Rifai

Reputation: 37

how implement acra to activity?

How to implement acra error report on activity or something else? I know it must be on class that extends application, but is it possible to add acra to activity?

I'm getting the following error

cannot be cast to android.app.application

This is my code

@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));
}

Upvotes: 2

Views: 900

Answers (3)

BlaShadow
BlaShadow

Reputation: 11693

You don't need to add acra to and activity you need to configure to an application class level.

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

<application android:icon="@drawable/icon" android:label="@string/app_name"                   android:name="MyApplication">

Permition

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

follow this basic setup

Upvotes: 3

Andrey  Kopeyko
Andrey Kopeyko

Reputation: 1566

As colleagues already have told you, ACRA is added to entire application. So, add ACRA to your app, but use it only in desired Activity.

Upvotes: 1

William
William

Reputation: 20196

No. ACRA is added to your entire application. If you don't already have an Application class just create one that extends from Application.

Upvotes: 2

Related Questions