Example usage for android.hardware.usb UsbConstants USB_CLASS_STILL_IMAGE

List of usage examples for android.hardware.usb UsbConstants USB_CLASS_STILL_IMAGE

Introduction

In this page you can find the example usage for android.hardware.usb UsbConstants USB_CLASS_STILL_IMAGE.

Prototype

int USB_CLASS_STILL_IMAGE

To view the source code for android.hardware.usb UsbConstants USB_CLASS_STILL_IMAGE.

Click Source Link

Document

USB class for still image devices (digital cameras).

Usage

From source file:com.dslr.dashboard.PtpService.java

public void searchForUsbCamera() {
    boolean deviceFound = false;
    try {//w w w . j a  v a  2 s. c o  m
        if (mUsbDevice == null) {
            Log.d(TAG, "Ptp service usb device not initialized, search for one");

            if (mUsbManager != null) {
                HashMap<String, UsbDevice> devices = mUsbManager.getDeviceList();
                Log.d(TAG, "Found USB devices count: " + devices.size());
                Iterator<UsbDevice> iterator = devices.values().iterator();
                while (iterator.hasNext()) {
                    UsbDevice usbDevice = iterator.next();
                    Log.d(TAG,
                            "USB Device: " + usbDevice.getDeviceName() + " Product ID: "
                                    + usbDevice.getProductId() + " Vendor ID: " + usbDevice.getVendorId()
                                    + " Interface count: " + usbDevice.getInterfaceCount());
                    for (int i = 0; i < usbDevice.getInterfaceCount(); i++) {
                        UsbInterface intf = usbDevice.getInterface(i);
                        Log.d(TAG, "Interface class: " + intf.getInterfaceClass());
                        if (intf.getInterfaceClass() == android.hardware.usb.UsbConstants.USB_CLASS_STILL_IMAGE) {
                            //mUsbDevice = usbDevice;
                            Log.d(TAG, "Ptp Service imaging usb device found requesting permission");
                            mUsbManager.requestPermission(usbDevice, mPermissionIntent);
                            deviceFound = true;
                            break;
                        }
                    }
                    if (deviceFound)
                        break;
                }
            } else
                Log.d(TAG, "USB Manager is unavailable");

        } else {
            Log.d(TAG, "Ptp service usb imaging device already present");
            //_usbManager.requestPermission(_usbDevice, mPermissionIntent);
        }
    } catch (Exception e) {
        Log.d(TAG, "PtpService search for USB camrea exception: " + e.getMessage());
    }

}

From source file:com.dslr.dashboard.PtpService.java

private void initUsbConnection() {

    try {//from w  w  w .jav  a 2 s . c  om
        if (mUsbDevice != null) {
            if (mUsbIntf == null) {
                for (int i = 0; i < mUsbDevice.getInterfaceCount(); i++) {
                    UsbInterface uintf = mUsbDevice.getInterface(i);
                    if (uintf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE) {
                        // we have a still image interface
                        // Log.d(MainActivity.TAG, "Imaging USB interface found");
                        mUsbIntf = uintf;
                        break;
                    }
                }
                if (mUsbIntf != null) {
                    // get the endpoints
                    for (int i = 0; i < mUsbIntf.getEndpointCount(); i++) {
                        UsbEndpoint ep = mUsbIntf.getEndpoint(i);
                        if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
                            if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                                mUsbWriteEp = ep;
                                // Log.d(MainActivity.TAG, "write endpoint found");
                            }
                        } else {
                            switch (ep.getType()) {
                            case UsbConstants.USB_ENDPOINT_XFER_BULK:
                                mUsbReadEp = ep;
                                // Log.d(MainActivity.TAG, "read endpoint found");
                                break;
                            case UsbConstants.USB_ENDPOINT_XFER_INT:
                                mUsbInterruptEp = ep;
                                // Log.d(MainActivity.TAG, "interrupt endpoint found");
                                break;
                            }
                        }
                    }
                } else
                    Log.d(TAG, "No compatible USB interface found");
            } else
                Log.d(TAG, "USB interface found");
            // if we have read and write endpoints then we good to go
            if (mUsbReadEp != null && mUsbWriteEp != null) {
                if (!mIsUsbDeviceInitialized) {
                    mUsbConnection = mUsbManager.openDevice(mUsbDevice);
                    mIsUsbDeviceInitialized = mUsbConnection != null;
                }
                if (mIsUsbDeviceInitialized) {
                    // Log.d(TAG, "USB Device Initialized");
                    if (!mIsUsbInterfaceClaimed) {
                        mIsUsbInterfaceClaimed = mUsbConnection.claimInterface(mUsbIntf, true);
                        // Log.d(TAG, "USB Interface claimed: " + isInterfaceClaimed);
                    }
                    sendPtpServiceEvent(PtpServiceEvent.UsbDeviceInitialized);
                    // create the USB communicator
                    PtpUsbCommunicator communicator = new PtpUsbCommunicator(new PtpSession());
                    // initialize the USB communicator
                    communicator.initCommunicator(mUsbConnection, mUsbWriteEp, mUsbReadEp, mUsbInterruptEp);
                    // initialize the PTP device
                    mPtpDevice.initialize(mUsbDevice.getVendorId(), mUsbDevice.getProductId(), communicator);
                }
            }

        } else
            Log.d(TAG, "No USB device present");

    } catch (Exception e) {
        Log.d(TAG, "InitUsb exception: " + e.getMessage());
    }
}