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.
Asked
Active
Viewed 2.4k times
39
-
1http://stackoverflow.com/questions/4276857/getting-debuggable-value-of-androidmanifest-from-code – Im0rtality Aug 11 '11 at 08:12
-
@Imortality...thanks for cooperation but it is not working in my case. – Usama Sarwar Aug 11 '11 at 09:36
-
What exactly is debug mode and live mode then? – Im0rtality Aug 11 '11 at 10:24
3 Answers
31
It is not clear from the question whether debug mode refers to:
- Whether the app is debuggable or not
- Whether the app is currently being debugged (e.g. over ADB)
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()
-
There is a third 'debug' issue that also can be confused with this type of question, device developer option enablement. Determining whether the developer option is enabled so the production app can kill itself for security, like Fortnite does, is something I do with my game app and would recommend to anyone who doesn't want their intellectual property hacked. I found a solution by a relative newbie to stackoverflow votes here https://stackoverflow.com/questions/31581830/android-how-to-check-if-developer-option-is-enabled. – Androidcoder Nov 17 '20 at 15:11
-
First one shall be used. `android.os.Debug.isDebuggerConnected()` might get false when the debugger is trying to attach to the process but not yet. – Chester Fung May 06 '23 at 04:40
15
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

Ganesh Krishnan
- 7,155
- 2
- 44
- 52
13
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

android developer
- 114,585
- 152
- 739
- 1,270