Communication between Android and USB devices

18

I'm developing an Android application that communicates with a USB device, printer, Arduino, or other Android device.

Is it possible to read and write to Android's USB port? How do I proceed with the drivers? Does Android have libraries to work with USB devices? I've heard of a project called FTDI Chip to communicate with a USB device, am I on the right track?

    
asked by anonymous 25.02.2014 / 20:53

1 answer

9

There is a project on GitHub usb-serial-for-android

It's a library for communicating with Arduinos and other USB devices on Android using the Android USB Host API (Android 3.1+)

You do not need root access because you implement the drives in Java itself, which provides an api for Android to read and write to USB.

Follow the project link: link

Code snippet, see more in the sample project ( link )

// Encontra o UsbManager do Android.
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

// Encontra o primeiro Driver disponivel.
UsbSerialDriver driver = UsbSerialProber.acquire(manager);

if (driver != null) {
  driver.open();
  try {
    driver.setBaudRate(115200);

    byte buffer[] = new byte[16];
    int numBytesRead = driver.read(buffer, 1000);
    Log.d(TAG, "Read " + numBytesRead + " bytes.");
  } catch (IOException e) {
    // Deal with error.
  } finally {
    driver.close();
  } 
}

All are not flowers, as the project is still in version v0.1.0 and the last time it was updated was in 2012. At least the project is well documented.

I hope I have helped you.

    
25.02.2014 / 22:04