USB bulkTransfer between Android tablet and camera

I would like to exchange data/commands between a camera and an Android tablet device using the bulkTransfer function. I wrote this Activity, but the method bulkTransfer returns -1 (error status). Why does it return the error?

public class MainActivity extends Activity {

    private TextView text;
    private int TIMEOUT = 1000;

    protected void onCreate(Bundle savedInstanceState) {
        text = (TextView) findViewById(;

    private void usbTest() {
        UsbDevice device = (UsbDevice) getIntent().getParcelableExtra(
        if (device == null)
            text.setText("device null");
            text.setText("device not null");

        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
        text.setText(text.getText() + "\nDevices connected: "
                     + deviceList.values().size());
        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

        while (deviceIterator.hasNext()) {
            device =;
            text.setText(text.getText() + "\nDevice name: "
                         + device.getDeviceName());
            text.setText(text.getText() + "\nDevice protocol: "
                         + device.getDeviceProtocol());
            text.setText(text.getText() + "\nDevice id: "
                         + device.getDeviceId());
            text.setText(text.getText() + "\nDevice product id: "
                         + device.getProductId());
            text.setText(text.getText() + "\nDevice vendor id: "
                         + device.getVendorId());
            text.setText(text.getText() + "\nDevice class: "
                         + device.getDeviceClass());
            text.setText(text.getText() + "\nDevice subclass: "
                         + device.getDeviceSubclass());
            text.setText(text.getText() + "\nDevice interface count: "
                         + device.getInterfaceCount());
            text.setText(text.getText() + "\n\n");

        // communicate with device
        UsbInterface intf = device.getInterface(0);
        UsbEndpoint endpoint = intf.getEndpoint(0);
        UsbDeviceConnection connection = manager.openDevice(device);
        connection.claimInterface(intf, true);

        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;
                    text.setText("Found: "+i);

        // byte[] opensession = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02,
        // 0x10,
        // 0x00, 0x00, 0x00, 0x00 };
        // connection.bulkTransfer(endpoint, opensession, opensession.length,
        // TIMEOUT);

        byte[] getEvent = { 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, toByte(0xC7),
            toByte(0x90), 0x00, 0x00, 0x00, 0x00 };
        int status = connection.bulkTransfer(endpoint, getEvent,
                                             getEvent.length, TIMEOUT);
        //text.setText("Status: " + status);

        byte[] capture = { 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0E, 0x10,
            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00 };
        connection.bulkTransfer(endpoint, capture, capture.length, TIMEOUT);

        // teminate communication
        BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
                    UsbDevice device = (UsbDevice) intent
                    if (device != null) {
                        // call your method that cleans up and closes
                        // communication with the device


    public static byte toByte(int c) {
        return (byte) (c <= 0x7f ? c : ((c % 0x80) - 0x80));


  • Progressive Image Rendering, loading image pixel by pixel & updating imageview in imageLoader
  • Overflow button forces Action Mode to finish
  • Is there a way to reduce the spacing between the Action Item Icons on Action Bar?
  • limit scrolling and zooming Google Maps Android API v2
  • How to count number of records in sqlite in Android
  • Retain the Fragment object while rotating
  • Related posts:

    How to build i686-linux-android-gfortran for android-ndk8b (x86 arch Android)?
    Pop the fragment backstack without playing the Pop-Animation
    Can Android support dp&#039;s less than 1dp?
    How to enforce the custom permission on an Activity in Android?
    Design Support TabLayout
    Is it possible to use SIM card cryptographic functions?
  • How to distinguish if given Context object is an Activity or a Service Context?
  • Android Live Wallpapers with OpenGL ES 2.0?
  • Intent Filter to Launch My Activity when custom URI is clicked
  • How to use setEmptyView() with custom list layout in ListFragment
  • Adding Cordova/Phonegap plugins behind a proxy
  • How to set the Default Value of a ListPreference
  • One Solution collect form web for “USB bulkTransfer between Android tablet and camera”

    I suspect you are not correctly searching for interface and endpoint.

    see explanation below.

    Suggestion: test if the endpoint if it is valid and try to match it with device descriptor.

    a interface can have multiple setting.

    AFAIK, for camera, their should be three alternate setting for the camera interface.

    • Zero Bandwidth — no endpoints inside — most possibly alternate setting 0
    • Isochronous (if the camera support it) — isochronous endpoint inside
    • Bulk — bulk endpoint inside <– place of you interest

    (I dont know the actual USB camera specification but, this should be applicable to all streaming protocol over USB (as i see in Audio Class))

    You need to search for the bulk alternate setting and then perform communication on the endpoint inside it.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.