Code example for UsbManager

Methods: getAccessoryListhasPermission

7
            //       Note however that the IDE still thinks that Gingerbread is required 
            //       thus the use of the `@TargetAPi(12)` above. 
            Class.forName("android.hardware.usb.UsbManager");
 
            UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
            UsbAccessory[] accessoryList = manager.getAccessoryList();
 
            // Note: The permissions check here is because sometimes we end up 
            //       with spurious accessories (e.g. ^B in the device description etc) 
            //       and presumably it also stops problems if an accessory is connected 
            //       when we're open. 
            result = ((accessoryList != null) && (manager.hasPermission(accessoryList[0])));
        } catch (ClassNotFoundException e) {
            Log.d(this.getClass().getSimpleName(),
                    "No USB accessory support, 'android.hardware.usb.UsbManager' not found."); 
        } 
 
        return result;
    } 
 
Contextual code suggestions in your IDE  Get Codota for Java