8

Is it possible to have an application detect when ADB is listening over USB on an Android phone?

I'm looking for something like this: Is it possible to determine whether an Android device is plugged into a computer or just power? but specifically for when ADB is running.

Thanks!

Community
  • 1
  • 1
lanrat
  • 4,344
  • 10
  • 35
  • 41
  • This might help - http://stackoverflow.com/a/7156252/2114852 – Sam May 24 '13 at 19:06
  • Good reference, but note that charging doesn't necessarily mean ADB - it might mean a charger. Also, is it important to differentiate between being connected to a PC without an SDK, vs one with the SDK and an active ADB server on the PC, vs one where there's an active channel open through ADB to a shell, logcat, push/pull operation, port forward, etc ? – Chris Stratton May 24 '13 at 19:18
  • 1
    I don't need to check if ADB is running on the computer as I don't thing that is possible. Just that the ADB service is running on the phone and listening over USB. Basically whenever the ADB notification is displayed. – lanrat May 24 '13 at 19:35

1 Answers1

4
Settings.Global.getInt(context.getContentResolver(), Settings.Global.ADB_ENABLED, 0);

Will return a 1 if USB Debugging is enabled on the phone and a 0 if it isn't.

ProjectDelta
  • 351
  • 4
  • 12
Jcooke
  • 65
  • 4