I have an external mass storage device connected to an Android device. There are several .BIN files in the root directory that I need to read into my app. I am able to connect to the device and receive usb permission using UsbDeviceConnection.
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String output = outputTV.getText().toString();
String action = intent.getAction();
outputTV.setText(outputTV.getText() + "\n" + " ACTION: " + action);
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) {
if (device.getInterfaceCount() > 0) {
usbIntf = device.getInterface(0);
usbEndIn = usbIntf.getEndpoint(0);
usbEndOut = usbIntf.getEndpoint(1);
usbConnection = mUsbManager.openDevice(device);
usbConnection.claimInterface(usbIntf, true);
byte[] buffer = new byte[usbEndIn.getMaxPacketSize()];
StringBuilder str = new StringBuilder();
int retVal = usbConnection.bulkTransfer(usbEndIn, buffer, usbEndIn.getMaxPacketSize(), 2000);
for (int i = 2; i < buffer.length; i++) {
if (buffer[i] != 0) {
str.append((char) buffer[i]);
}}}}}}}}};
Once I'm connected I am able to see that I have one Mass Storage interface with 2 Bulk Transfer endpoints (one in, one out).
When using usbConnection.bulkTransfer I receive -1 back and an empty buffer. So, I'm having trouble receiving data. Once past that hurdle, what will the data look like? How do I continue to pull all of the files from the device? Is there a way to transfer the data file by file to my app? Is there an all together better way of approaching this?