Hi, I am writing an app that is supposed to communicate with a camera via
USB, Samsung Galaxy S2 with Android 4.0.3 being the host. I have trouble
with understanding how it has to be done. I am trying via bulkTransfer and
the code goes like this:
char ch = (char)34;
char[] record = {'P',ch};
String r = record.toString();
byte[] bytes = r.getBytes(Charset.forName("ASCII"));
int TIMEOUT = 10000;
boolean forceClaim = true;
UsbManager mUsbManager = (UsbManager)
getSystemService(Context.USB_SERVICE);
UsbInterface intf = device.getInterface(0);
for (int i = 0; i < intf.getEndpointCount(); i++) {
UsbEndpoint ep = intf.getEndpoint(i);
if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
endpoint = ep;
//Integer dir = endpoint.getDirection();
UsbDeviceConnection connection =
mUsbManager.openDevice(device);
if(connection!=null){devMessage+=" I connected";}
connection.claimInterface(intf, forceClaim);
Integer res = connection.bulkTransfer(endpoint, bytes,
bytes.length, TIMEOUT);
if (res>0){devMessage += "some data transfered.";}
connection.releaseInterface(intf);
break;
}
}
The data is being sent, at least that's what I get from the bulkTransfer()
method reaction. But nothing is happening. The command that I need to send
is a simple 2-character string - P"
Please, if anyone is familiar with USB host functionality contact me. I've
seen apps in google play that serve as remote controllers for the DSLR, so
I know it is doable but I am really just a beginner with Android.
I appreciate any help, guys!
Thanks!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en