I'm in ICS and am attempting to get a receiver attached that will be called when a USB device and/or accessory is plugged in/out of the tablet.
Based on the documentation and other Stack questions, it *looks like all I should need is the code beneath, however when I run this code nothing happens... it's hard to tell, cause my device has the USB accessory being plugged into/out of it, so my debugging is just me writing stuff to file, rather than actual debugging, but it doesn't *appear to do anything at all.
IntentFilter attachFilter = new IntentFilter();
attachFilter.addAction(ACTION_USB_PERMISSION);
attachFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
registerReceiver(mAttachReceiver, attachFilter);
IntentFilter detachFilter = new IntentFilter();
detachFilter.addAction(ACTION_USB_PERMISSION);
detachFilter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
registerReceiver(mDetachedReceiver, detachFilter);
the receivers look like this (I've cut them down for brevity but they're valid receivers)...
private final BroadcastReceiver mAttachReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
logMsg("ACTION = " + action);
... }
}
And my manifest contains this entry:
<uses-feature android:name="android.hardware.usb.host" />
Is there something I'm missing? I've tried ACTION_USB_DEVICE_ATTACHED instead of ACCESSORY but that doesn't seem to produce any different results. Also, I CAN talk to the device in the app once its attached, so, it's being recognized and the subsequent code that sends/receives messages from the attached device (it's a NFC card reader) works as expected. The only thing that is persistently failing is the notification of the initial cable connection.
TIA