I've been looking at examples and I'm still not clear on how to actually read data from the usb port in my Android application. I'd like it to be event/intent driven but I'm pretty lost on how to do this. I have a BroadcastReceiver but I'm unsure what Intent.action I need to be looking for to catch data coming in. Any insight is appreciated!
Edit: To clarify my Android device is a Nexus 9 running as a USB Host and I'm looking to communicate with an Arduino Leonardo.
Edit2: At this point I have an Arduino sketch running sending a message over serial every 2 seconds. I have a button that based off of my understanding should read the buffer when pressed but doesn't actually do anything.
TextView displayMessages = (TextView)findViewById(R.id.textView);
try
{
byte[] msgBytes = new byte[1000];
connection.bulkTransfer(input, msgBytes, msgBytes.length, TIMEOUT);
String msgString = new String(msgBytes, "UTF-8");// msgBytes.toString();
displayMessages.setText(msgString);
}
catch (Exception e)
{
displayMessages.setText(e.getMessage());
}
The result is simply that the textView is blank. If I don't do the conversion and drop the byte[].toString() in I get hex values that change each press but I'm not sure how to interpret that.
Edit 3: Just some more information as some time has passed, I have disabled the Arduino Leonardo showing up as an HID keyboard input device as per Arduino being recognized as keyboard by android. I simply modified the USBDesc.h to remove "#define HID_ENABLED". This didn't change the situation. In the meantime I have also implemented the Physicaloid USB library and that proved unsuccessful as well. I am in the process of debugging/converting mik3y's USB-serial-for-android library but have so far been unable to test with it.