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.
Fabric on initialization creates a singleton instance and returns same instance whenever you call Fabric.with(...)
. So, your code inside onPreferenceChange
has 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());
来源:https://stackoverflow.com/questions/32168754/how-to-disable-crashlytics-fabric-at-runtime-when-user-changes-preferences