Question

I would like to provide a setting in my Android app's settings activity allowing the user to disable our use of analytics software, including Crashlytics. However, Crashlytics.start(Context) is called long before the user gets to the settings page, and I don't see an equivalent Crashlytics.stop(Context) function. Is it possible to stop Crashlytics within the app after it has been started?

Was it helpful?

Solution

I've been informed that the specific case I'm attempting is not currently possible. However, I can give users control over whether or not to send data to Crashlytics by enabling the "Privacy prompt" in the App settings part of the Crashlytics dashboard:

Go here to select the app you want to add the dialog to and then click on "Enable Privacy Prompt" in the top left corner.

from: https://docs.fabric.io/android/crashlytics/advanced-setup.html#using-the-privacy-dialog

OTHER TIPS

Crashlytics cannot be stopped once started but the behaviour you want can be reached via overriding the default UncaughtExceptionHandler:

    final Thread.UncaughtExceptionHandler defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    Fabric.with(this, new Crashlytics());
    final Thread.UncaughtExceptionHandler crashlyticsExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
        if (isAnalyticsAllowed) {
            crashlyticsExceptionHandler.uncaughtException(t, e);
        } else {
            defaultExceptionHandler.uncaughtException(t, e);
        }
    }); 

It's easy to do.

  1. Add a preference to your app settings and let the user descide wether he want do it or not.
  2. Implement UncaughtExceptionHandler and do like this
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(MyApplication.getAppContext());

        Boolean send = sharedPref.getBoolean(MySettingsActivity.KEY_PREF_SEND_ERROR, true);

        if (send) {
            orgHandler.uncaughtException(thread, ex);
        } else {
            System.exit(0);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top