How to check programmatically whether app is running in debug mode or not?

It is not clear from the question whether debug mode refers to:

  1. Whether the app is debuggable or not
  2. 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()

Leave a Comment