想用Google ADK来进行开发,用如下代码检测是不是有设备连接进来,但是不管用什么设备好像都没有反应。这是为什么呢。求高手能够告知一下,感激不尽啊。。
String content = new String();
   content += "begin..........";
   UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
   HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
   Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
   while(deviceIterator.hasNext()){
       UsbDevice device = deviceIterator.next();
       content += device.getDeviceName();
   }
   content += "end............";
关于权限的android.hardware.usb.host.xml已经有了
handheld_core_hardware.xml里也添加了<feature name="android.hardware.usb.host" />
GoogleADKusb host设备连接

解决方案 »

  1.   

    我用android usb host模式与arduino板子进行通信。现在可以获取设备,发送消息貌似都没什么问题了。但是接收消息出现了一些问题。
    UsbEndpoint endpoint2 = intf.getEndpoint(0);
     byte[] bytes2 = new byte[10];
     int ret = connection.bulkTransfer(endpoint2, bytes2,bytes2.length, 3000);
     String content2 = new String();
     content2 += "ret:" + ret + "\n";
     if (ret > 0) {
     String str = new String(bytes2);
     content2 += "数据内容--->" + str;
     }
     receive.setText(content2);
    代码如上,我的想法是接收到数据。把返回值和内容在一个textView中显示出来。现在显示的结果是ret:2 内容没有显示。我发送的内容不止两个字节。反正就是内容接收有问题。请问大家碰到过这种情况么?  有什么解决的办法么? 谢谢了~~~