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?
问问题
2082 次
3 回答
3
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
于 2014-04-30T21:14:04.040 回答
1
这很容易做到。
- 为您的应用设置添加首选项,让用户决定是否要这样做。
- 实现 UncaughtExceptionHandler 并这样做
@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);
}
}
于 2015-10-04T09:39:28.347 回答
1
Crashlytics 一旦启动就无法停止,但可以通过覆盖默认的 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);
}
});
于 2018-11-06T15:08:31.443 回答