是否可以在Android设备上检测USB调试?

And*_*per 10 debugging usb android

在我的应用程序中,我需要一种方法来检测android设备是否在USB调试模式下运行.

可能吗?如果有,怎么样?

提前

Rag*_*ood 21

您可以使用以下命令来获取是否启用了ADB.

int adb = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
Run Code Online (Sandbox Code Playgroud)

如果已启用adb == 1,否则adb == 0.

  • 在API级别17中不推荐使用Settings.Secure.ADB_EN​​ABLED.而是使用Settings.Global.getInt(context.getContentResolver(),Settings.Global.ADB_EN​​ABLED,0) (6认同)