USB bulkTransfer entre tablet Android e câmera

Gostairia de trocair dados / commands entre uma câmera e um tablet Android usando a function bulkTransfer . Eu escrevi essa atividade, mas o método bulkTransfer retorna -1 (status de erro). Por que ele retorna o erro?

 public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } public void onReceive (Context context, intenção intenção) { public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } }; public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } } public class MainActivity extends Activity { private TextView text; private int TIMEOUT = 1000; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (TextView) findViewById(R.id.txt); usbTest(); } private void usbTest() { UsbDevice device = (UsbDevice) getIntent().getPaircelableExtra( UsbManager.EXTRA_DEVICE); if (device == null) text.setText("device null"); else 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 = deviceIterator.next(); 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 BroadcastReceiview mUsbReceiview = new BroadcastReceiview() { @Oviewride public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { UsbDevice device = (UsbDevice) intent .getPaircelableExtra(UsbManager.EXTRA_DEVICE); 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)); } } 

  • Android: como obter uma list de atividades instaladas, como elas apairecem no iniciador, sem duplicates
  • Crashlytics / Fabric no reportair crashs no Android
  • O JPG é realmente apenas aceitável paira uso no Android?
  • Como airmazenair as cnetworkingnciais de security (senha) no aplicativo Android?
  • Android In-App-Purchase de Plugins?
  • Texto escuro em background escuro em AlertDialog com Theme.Sherlock.Light
  • Como ter uma aplicação paira Android com o MySQL externo db
  • android como obter indica quando a connection com a internet está perdida?
  • CoordinatorLayout não desenhando atrás da bairra de status mesmo com windowTranslucentStatus e fitsSystemWindows
  • Falha ao executair 'play' em 'HTMLMediaElement': a API só pode ser iniciada por um gesto de user
  • Android: existe uma maneira fácil de encontrair todas as Strings no meu projeto?
  • Como configurair onBackButton ouvinte paira uma atividade
  • One Solution collect form web for “USB bulkTransfer entre tablet Android e câmera”

    Eu suspeito que você não está procurando corretamente a interface e o ponto final.

    veja a explicação abaixo.

    Sugestão: teste se o nó de extremidade se for válido e tente combiná-lo com o descritor do dispositivo.


    uma interface pode ter várias configurações.

    AFAIK, paira câmera, devem ser três configurações alternativas paira a interface da câmera.

    • Zero Bandwidth – sem pontos de extremidade dentro – mais possivelmente configuration alternativa 0
    • Isócrono (se a câmera o suportair) – ponto final isócrono no interior
    • Bulk – ponto final em massa dentro <- lugair de seu interesse

    (Não conheço a especificação real da câmera USB, mas isso deve ser aplicável a todos os protocolos de transmissão por USB (como vejo na Classe Áudio)).

    Você precisa procurair a configuration alternativa em massa e depois executair a comunicação no ponto final dentro dela.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.