android - USB HID device not detected by Application -
private final broadcastreceiver musbreceiver = new broadcastreceiver() { public void onreceive(context context, intent intent) { string action = intent.getaction(); if (action_usb_permission.equals(action)) { synchronized (this) { setdevice(intent); } } if (usbmanager.action_usb_device_attached.equals(action)) { synchronized (this) { setdevice(intent); } if (device == null) { mlog("device connected"); } } if (usbmanager.action_usb_device_detached.equals(action)) { if (device != null) { device = null; btnsend.setenabled(false); } mlog("device disconnected"); } } private void setdevice(intent intent) { device = (usbdevice) intent.getparcelableextra(usbmanager.extra_device); if (device != null && intent.getbooleanextra(usbmanager.extra_permission_granted, false)) { mlog("selected device vid:" + integer.tohexstring(device.getvendorid()) + " pid:" + integer.tohexstring(device.getproductid())); connection = musbmanager.opendevice(device); intf = device.getinterface(0); if (null == connection) { mlog("(unable establish connection)\n"); } else { connection.claiminterface(intf, true); } try { if (usbconstants.usb_dir_out == intf.getendpoint(1).getdirection()) { endpointwrite = intf.getendpoint(1); } } catch (exception e) { log.e("endpointwrite", "device have no endpointwrite", e); } try { if (usbconstants.usb_dir_in == intf.getendpoint(0).getdirection()) { endpointread = intf.getendpoint(0); packetsize = endpointread.getmaxpacketsize(); } } catch (exception e) { log.e("endpointwrite", "device have no endpointread", e); } btnsend.setenabled(true); } } }; void showlistofdevices() { btnsend.setenabled(false); alertdialog.builder builder = new alertdialog.builder(this); musbmanager = (usbmanager) getsystemservice(context.usb_service); if (musbmanager.getdevicelist().size() == 0) { builder.settitle(message_connect_your_usb_hid_device); } else { builder.settitle(message_select_your_usb_hid_device); } list<charsequence> list = new linkedlist<charsequence>(); for (usbdevice usbdevice : musbmanager.getdevicelist().values()) { list.add("devid:" + usbdevice.getdeviceid() + " vid:" + integer.tohexstring(usbdevice.getvendorid()) + " pid:" + integer.tohexstring(usbdevice.getproductid()) + " " + usbdevice.getdevicename()); } final charsequence devicesname[] = new charsequence[musbmanager.getdevicelist().size()]; list.toarray(devicesname); builder.setitems(devicesname, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { device = (usbdevice) musbmanager.getdevicelist().values().toarray()[which]; musbmanager.requestpermission(device, mpermissionintent); } }); builder.setcancelable(true); builder.show(); }
i develeped application read serial data usb hid device. works fine on nexus 7 tablet. trying read incoming serial data usb hid device connected pcduino3 (android os 4.2.2) application. unable detect usb hid device app. used usb host api.
however able detect device through terminal window. device details
product id : 0010
vender id : 1658
here observation of project. in terminal emulator when give command "ls /dev/usb", following output:
@android: / $ ls/dev/usb
hiddev0
input3-1.1
input3-1.2
input3-1.4
when give command "busybox lsusb" following output:
@android: / $ busybox lsusb
bus 001 device 002 : id 0bda:8179
bus 003 device 002 : id 1a40:0101
bus 001 device 001 : id 1d6b:0002
bus 002 device 001 : id 1d6b:0001
. . .
. . .
bus 003 device 007 : id 1658:0010
can 1 me resolve problem or enlighten me on going on?
Comments
Post a Comment