How to check usb debugging enabled programmatically?
Asked Answered
H

2

12

my question is on an Android phone how can I check if the usb debugging flag is enabled or not programmatically? in my application I want to show the status of usb debugging and I want to get it programmatically

How can I get if usb debugging is enabled programmatically?

Hellas answered 10/9, 2013 at 10:44 Comment(0)
M
20

Try this:

if(Settings.Secure.getInt(context.getContentResolver(), Settings.Global.ADB_ENABLED, 0) == 1) {
    // debugging enabled 
} else {
    //;debugging does not enabled
}
Marylandmarylee answered 10/9, 2013 at 10:50 Comment(3)
I notice that ADB_ENABLED now has a line through it, with a message that 'ADB_ENABLED' is deprecated as of Android 17 (Jelly Bean)' on the mouseover. I don't see any promising suggestions on the autocomplete list after 'Secure.' Anyone know what the current syntax is for this?Garica
Try Settings.Global instead of Settings.Secure on android API levels 17+Crystallization
if(Settings.Secure.getInt(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) == 1)Devanagari
H
0

Simple:

   boolean isDebuggable =  ( 0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE ));

And if you want to check if it is connected:

if (!Debug.isDebuggerConnected()){
   //Yes, it is.
}
Hagans answered 5/2, 2017 at 22:29 Comment(1)
The question is about whether or not USB debugging is enabled, not if the app is debuggable or being debugged. Still useful thoughRegistrant

© 2022 - 2024 — McMap. All rights reserved.