禁用基于用户设置Crashlytics /答案 [英] Disable Crashlytics/Answers based on user setting

查看:326
本文介绍了禁用基于用户设置Crashlytics /答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序添加一个新的preference,允许用户选择退出的分析报告。我使用我的应用程序Crashlytics和答案由织物。

I am adding a new preference on my app, to allow the user to opt out of analytics reports. I am using in my app Crashlytics and Answers by Fabric.

我在这的onCreate code:

I have this code within onCreate:

if (PreferenceHelper.getAllowAnalytics(context)) {
            Fabric.with(this, new Crashlytics());
        } else {
            //no crash or answers to be sent
        }
}

和我想送一个事件,每次我这样做,是这样的:

and each time I want to send an event I do it like this:

Answers.getInstance().logCustom(new CustomEvent("test event"));

这工作得很好,当用户允许它。
我应该如何处理其他当用户决定不让解析?

This works well, when the user allows it. How should I handle the else when the user decides not to allow analytic?

推荐答案

您可以包装所有的在一个新的类,它会检查你的preference和无助调用Answers.getInstance的,如果它不启用? IE:。相反Answers.getInstance()的logCustom()WrappedAnswers.getInstance()logCustom()。裹的答案会做logCustom()你的if / else检查

You could wrap all of your calls to Answers.getInstance in a new class that checks your preference and does nothing if it's not enabled? IE: Instead of Answers.getInstance().logCustom() WrappedAnswers.getInstance().logCustom(). And wrapped answers would do your if/else check in logCustom()

这篇关于禁用基于用户设置Crashlytics /答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆