6

I am using com.crashlytics.sdk.android:crashlytics:2.3.2@aar version of crashlytics and i disable crash reporting if user opt out.

I tried this solution but still it is not working, crash reports are still being sent to Fabric.

I am doing it as:

Preference errorReportingEnabled = findPreference(MatlistanPrefs.BUGREPORTS_SEND_AUTOMATICALLY);
    errorReportingEnabled.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {

            Boolean value = (Boolean) newValue;

            Fabric.with(DataCollectionSettingsActivity.this, new Crashlytics.Builder().
                    core(new CrashlyticsCore.Builder().disabled(!value).build())
                    .build());
            return true;
        }
    });

Is there any working solution for this problem?

Thanks.

Community
  • 1
  • 1
Shajeel Afzal
  • 5,913
  • 6
  • 43
  • 70

1 Answers1

5

Fabric on initialization creates a singleton instance and returns same instance whenever you call Fabric.with(...). So, your code inside onPreferenceChangehas no effect on Fabric class.

The only solution to this problem can be if library itself provide methods for enabling or disabling crashlytics. So, up-till now (crashlytics:2.5.2) there is no solution to enable/disable crashlytics at run-time. You have to do it at startup like this:

Fabric.with(this, new Crashlytics.Builder()
    .core(new CrashlyticsCore.Builder()
    .disabled(true).build()).build());