[英]Android debug / release version of application
I have one question about finding if your application is in release mode or in debug. 我有一个问题要查找您的应用程序是处于发布模式还是调试状态。 I need to find a way to detect the applications mode automatically with a function.
我需要找到一种通过功能自动检测应用程序模式的方法。 For now I'm using a simple way declaring a
boolean
which everytime I have to change true/false
. 现在,我正在使用一种简单的方法来声明一个
boolean
,每次我必须更改true/false
。 But sometimes me, or the other developer may forget to change it. 但是有时候,我或其他开发人员可能忘记更改它。 Actually I need this because, I'm using an error handler in my app which is sending to our server exceptions which are uncaught.
实际上,我需要这样做是因为,我在我的应用程序中使用了一个错误处理程序,该错误处理程序会将未捕获的异常发送到我们的服务器。 And I don't want to do this in debug mode.
而且我不想在调试模式下执行此操作。
So is there any way I can detect this with some functions which my app will do automatically, without using any variables like I do? 那么,有什么方法可以使用我的应用程序将自动执行的某些功能检测到此情况,而无需像我一样使用任何变量?
There is no general solution but you may use isDebuggerConnected . 没有通用的解决方案,但是您可以使用isDebuggerConnected 。
BUT this solution would also trigger/show the debug features if your users connect their phones to the PC and uses ddms themselves. 但是,如果您的用户将手机连接到PC并自己使用ddms,则此解决方案还将触发/显示调试功能。
Maybe you sould combine this with one of the checks Aleks G suggested, and popup a Toast-message on every start that reminds you to disable debug ;-) 也许您将这与Aleks G建议的一项检查结合在一起,并在每次启动时弹出Toast消息,提醒您禁用调试;-)
Why not use this? 为什么不使用这个?
if (BuildConfig.DEBUG) {
// what shall happen in debug version
} else {
// release version
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.