androidusbandroid-open-accessory

How to find if Android Handset or Tablet supports Android Open Accessory (AOA) protocol?


I am developing an application to interface an accessory using Android Open Accessory (AOA) protocol.

I test the application using either a handset(Android 4.2.2) or a tablet (Android 4.1). Both these devices have USB Micro-B receptacle, whereas, accessory has USB A type receptacle. I use Micro-B plug to USB-A plug cable to connect any one of the earlier mentioned Android device with Accessory.

The application is expected to popup as soon as accessory is connected to handset or Tablet.

It is working as expected on handset but not on the tablet. After putting good amount of time on debugging this issue, it is occurring to me that the tablet may not be supporting AOA Protocol. (JFYI: The table supports OTG mode).

Therefore my questions are:

1) Has anyone came across any app which can inform whether device supports AOA or not? 2) Does anyone know programmatic way to detect support for AOA on android device?

Thanks in advance for forthcoming help from community members.

P.S. I have already read answer for similar issue mentioned at - 1) How to tell if an Android device has Open Accessory Mode 2) Does the Acer Iconia Tab A500 support Accessory mode? 3) What Android Tablet Currently Supports Accessory Mode for ADK Development 4) Which android devices support the ADK / open accessory - without any outcome.


Solution

  • I found the answer. The android app can be programmed to detect if the USB accessory mode is supported or not. The trick is to use android PackageManager to verify FEATURE_USB_ACCESSORY is present or not on the phone or tablet. Given below is a relevant code snippet:

            PackageManager pm;
            pm = getActivity().getPackageManager();
            boolean isUSBAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
    
            if(!isUSBAccessory){
                Toast.makeText(getActivity(), "USB Accessory not supported", Toast.LENGTH_SHORT).show();
            }else {
                Toast.makeText(getActivity(), "USB Accessory supported", Toast.LENGTH_SHORT).show();
            }
    

    This code is test on a phone and a tablet, as mentioned in the question. The phone toasts the message "USB Accessory supported", where as, the tablet toasts "USB Accessory not supported".