Search code examples
androidusbhostaccessory

Reconnected USB Accessory not detected by Android App


I successfully setup a Activity for listening to "android.hardware.usb.action.USB_ACCESSORY_ATTACHED" and a BroadcastReceiver for listening to "android.hardware.usb.action.USB_ACCESSORY_DETACHED". They both work fine if I have just installed the app.

However, if the file descriptor of the accessory was opened once, followed by disconnecting the accessory, I would no longer receive ATTACHED or DETACHED events if I connect / disconnect the accessory. When listing connected accessories using UsbManager, I get back null array.

If I reinstall the app, everything works fine again (for one time).

Any ideas why this is happening?


Solution

  • Turns out that I was actually not closing the file description that I got after opening the USB accessory. Closing it fixed the problem.