How to connect an OutputStream to an UsbDeviceConnection in Android?

Wednesday, July 2, 2014

I need to connect an Android device to a thermal printer (DDP-250) thru an USB cable.



  • The Android device has USB Host capabilities.

  • The thermal printer has an USB interface.


So far, I'm already able to create an UsbDeviceConnection to the printer.


The tricky part is that the printer's SDK works based on an OutputStream to send data to the device.


From the javadoc:



Printer(java.io.OutputStream out)
Constructs a new instance of this class from a given OutputStream.


This means that sending data using UsbDeviceConnection.bulkTransfer is not an option. I need to, somehow, get an OutputStream that streams data to the UsbDeviceConnection.


I even thought about using UsbDeviceConnection.getFileDescriptor to create a FileOutputStream, but UsbDeviceConnection.getFileDescriptor just returns an integer.


Oh, just to be clear, i know this printer has a bluetooth interface. But while using it, i was having wifi instability problems. And i need to have access to both, wifi internet and the printer, at the same time. I also tried to connect the android device to the internet using an usb/ethernet adapter (in this case the thermal printer would stay connected thru Bluetooth), but this android device does not have ethernet capabilities.


Any ideas? Anything at all. I'll take anything, even the recommendation of another thermal printer.


Thanks!







http://ift.tt/1qpfrPE