我的问题是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.