如何通过编程方式检查usb调试?

Nej*_*eji 8 android usb-debugging

我的问题是在Android手机上,如何以编程方式检查是否启用了usb调试标志?在我的应用程序中,我想显示usb调试的状态,我想以编程方式获取它

如果以编程方式启用usb调试,我该怎么办?

DrM*_*ens 11

试试这个:

if(Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ADB_ENABLED, 0) == 1) {
    // debugging enabled 
} else {
    //;debugging does not enabled
}
Run Code Online (Sandbox Code Playgroud)

  • 在 Android API 级别 17+ 上尝试使用 Settings.Global 而不是 Settings.Secure (2认同)