Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check USB Connection Status on Android

Tags:

android

I was wondering if would be possible to perform an action for each time the USB status of the device changes.

For example if the user plugs in the cable and it is in sync/charge mode it performs a certain action, if the user then changes the phone into USB Memory Card mode another action is performed and if the user then disconnects the cable then the another action is done.

Is this actually possible?

like image 759
Boardy Avatar asked Feb 16 '26 03:02

Boardy


1 Answers

Is this actually possible.

Sure.

Android broadcasts various Intents that you can listen to with a BroadcastReceiver. Among these are:

  • ACTION_BATTERY_CHANGED (tells you if device is plugged into USB or AC)
  • ACTION_UMS_CONNECTED and ACTION_UMS_DISCONNECTED (tells you if device enters or leaves USB Mass Storage mode)
like image 135
CommonsWare Avatar answered Feb 17 '26 17:02

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!