Reputation: 9020
I have to identify at some place in my app that, whether my app is running in debug mode or live mode. Is there any function or piece of code available to check that. that returns true/false in either case on/off. if so, please help me out. Thanks in advance.
Upvotes: 39
Views: 25178
Reputation: 7395
if (BuildConfig.DEBUG) {
// here be thine debug statement
}
Works really well across eclipse and Android Studio.
The other ones mentioned here often throws runtime exceptions for me
Upvotes: 15
Reputation: 116070
In case by "live mode" you mean signed for use on the play store, you can differentiate between the 2 states by checking the value of BuildConfig.DEBUG . Google has shown a video about it here
Upvotes: 13
Reputation: 7728
It is not clear from the question whether debug mode refers to:
The first is covered by CommonsWare's answer:
boolean isDebuggable = 0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE);
The second is:
boolean isBeingDebugged = android.os.Debug.isDebuggerConnected()
https://developer.android.com/reference/android/os/Debug.html#isDebuggerConnected()
Upvotes: 31