4

I want to establish serial communication between Android and Arduino. My Android device supports OTG. When I run this code, I get empty result. (I've tried SanDisk USB, Arduino, USB Bluetooth).

TextView tv = (TextView)findViewById(R.id.text);
tv.setText("Hello");
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();
  tv.setText(device.getDeviceName());

AndroidManifest;

<uses-sdk
  android:minSdkVersion="12"
  android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.hardware.usb.host"/>

Where is my error? (Sorry for my bad English.)

dda
  • 6,030
  • 2
  • 25
  • 34
  • Check [this](http://stackoverflow.com/questions/16006889/usbmanager-getdevicelist-returns-empty) and [this](http://stackoverflow.com/questions/13299393/getdevicelist-always-empty) links – Hana Bzh Jan 04 '15 at 11:43
  • I have tried before this. Nothing Changed :) @HBizhi –  Jan 04 '15 at 11:45
  • Perhaps your phone doesn't actually support OTG, or your adapter cable isn't grounding the id pin. Does plugging in a usb mouse or keyboard work? – Chris Stratton Jan 04 '15 at 15:36
  • 1
    Your code is broken though, as you keep writing the results in the same text view so only the last will show. You probably want to append them or use some sort of list view. – Chris Stratton Jan 04 '15 at 15:38
  • Yes, I've tried plugging usb mouse and keyboard. There are working :) @ChrisStratton –  Jan 06 '15 at 15:03
  • If result are be not empty, textView text will be changed. @ChrisStratton –  Jan 06 '15 at 15:06
  • The only value you are likely to see will be the last one. While probably not your primary problem, it's not hard to imagine cases where that could appear empty even when other entries are not. – Chris Stratton Jan 06 '15 at 15:22

0 Answers0