I would like to build an android application in Eclipse that sends data through a port. As per my thought, start screen will have a textfield and button. Whenever a text is typed and button pressed, the text has go through the port and received at an end. My objective is only to send the text data through the port. To achieve this, please guide me with code. Thank you
Asked
Active
Viewed 1,551 times
1
-
1This question appears to be off-topic because it is a "give me teh codes" question. – Ian Kemp Feb 13 '14 at 07:28
2 Answers
0
You will be require to study Accessory Development Kit class for this.
Android accessories can be audio docking stations, exercise machines, personal medical testing devices, weather stations, or any other external hardware device that adds to the functionality of Android.

user3301551
- 350
- 1
- 14
0
You have to connect the usb via usb manager this should happen after permission granted for that usb
UsbManager manager = (UsbManager) this.getSystemService(Context.USB_SERVICE);
UsbDeviceConnection connection = manager.openDevice(device);
get Interface and End points
UsbEndpoint epIN = null;
UsbEndpoint epOUT = null;
UsbInterface usbIf = dev.getInterface(0); // inter will change according to usb 0/1 etc..
for (int i = 0; i < usbIf.getEndpointCount(); i++) {
if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK){
if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
epIN = usbIf.getEndpoint(i);
else
epOUT = usbIf.getEndpoint(i);
} else {
Log.d("USB","Not Bulk");
}
}
Transfer text to usb
byte[] str = get.getBytes("TEXT");
connection.bulkTransfer(epOUT, str, str.length, 500);
hope it helps.

Poovizhirajan N
- 1,263
- 1
- 13
- 29