Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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.

like image 348
Usama Sarwar Avatar asked Aug 11 '11 08:08

Usama Sarwar


People also ask

How do you check if APK is debug or release programmatically?

There are different way to check if the application is build using debug or release certificate, but the following way seems best to me. According to the info in Android documentation Signing Your Application, debug key contain following subject distinguished name: "CN=Android Debug,O=Android,C=US".

How do I know if an app is running or not?

There are a few ways to see what apps are running in the background and consuming your Android's resources. Go to Settings > System > Developer Options. If you don't see Developer Options, scroll down and select About phone, then look for Build number and tap it seven times. Tap Running Services.


1 Answers

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()

like image 140
Mark Avatar answered Oct 05 '22 19:10

Mark