Ok, so I have a Android 3.1 tablet (Acer Iconia Tab, which is great by the way) which I can use with Android USB API to connect with a USB Mass Storage Device (a simple USB memory stick).
I use USB Host mode, find the device, get permission to connect to it (using BroadcastReceiver). All works great. The problem is that I don't know exactly what to do in order to copy a file from the External Storage Directory to the USB memory stick.
This is what I have so far:
final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
// Got to a point where I should set up connection
// I'm setting up a very simple connection, just want some file transfer
UsbInterface intf = device.getInterface(0);
UsbEndpoint endpoint = intf.getEndpoint(0);
UsbDeviceConnection connection = UsbManager.openDevice(device);
if (connection.claimInterface(intf, true)) {
UtilsAndDialogs.print(getApplicationContext(), "Connected to device");
// Copy file to USB...
} else
UtilsAndDialogs.print(getApplicationContext(), "Could not connect!");
}
} else {
UtilsAndDialogs.print(getApplicationContext(), "Permission denied");
Log.d(UtilsAndDialogs.LOG_TAG, "Permission denied for device " + device);
}
}
}
};
I read the documentation on the Android Dev Usb Host but it's not very explicit and I found a pretty good tutorial Android Usb Host Tutorial - AdbTest but it uses asynchronous communication.
I just want to know how should I set up the connection and use the endpoint (I didn't get the endpoint part, why they are needed) to just be able to create a new file on the USB storage device and copy contents of a different file in there, probably using bulkTransfer() method.
Any hints or pointers to more explicit documentation would be greatly appreciated.
Thank you