在开发时,可以禁用谷歌Analytics(分析) [英] Disable Google Analytics when in development

查看:735
本文介绍了在开发时,可以禁用谷歌Analytics(分析)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是pretty的简单:有什么办法为谷歌Analytics(分析)在应用程序的调试证书签名将自动禁用?意味着它应该只在发布版本是活动的。谢谢你在前进。

My question is pretty simple: is there any way for Google Analytics to be disabled automatically when the application is signed with the debug certificate? Means it should be active only in release version. Thank you in advance.

推荐答案

如果您正在使用ADT 17岁以上,你可以利用BuildConfig类:

If you're using ADT 17 and above, you can utilize the BuildConfig class:

if(BuildConfig.DEBUG) {
    GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
    googleAnalytics.setAppOptOut(true);
}

BuildConfig 类会自动像 R.java产生是。它只包含 DEBUG 布尔值,它被设置为默认情况下,和当你导出的apk。

The BuildConfig class is automatically generated like R.java is. It only contains the DEBUG boolean, which is set to true by default, and to false when you export an apk.

这篇关于在开发时,可以禁用谷歌Analytics(分析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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