如何禁用Crashlytics /布料在运行时,当用户更改preferences [英] How to Disable Crashlytics/Fabric at Runtime when User Changes Preferences
问题描述
我使用crashlytics的 com.crashlytics.sdk.android:crashlytics:2.3.2@aar
版本,我停用崩溃报告,如果用户选择退出。
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.
我这样做是:
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?
感谢。
推荐答案
在初始化面料创建一个单一实例,并返回当你调用同一个实例 Fabric.with(...)
。因此,在您code上preferenceChange
对面料类中没有效果。
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.
到这个问题的唯一解决方案可以是,如果库本身提供用于启用或禁用crashlytics方法。因此,向上,直到现在( crashlytics:2.5.2
)有无解启用/禁用crashlytics在运行时间。你必须在这样启动时做到这一点:
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());
这篇关于如何禁用Crashlytics /布料在运行时,当用户更改preferences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!