Example usage for android.hardware.usb UsbDevice getProductId

List of usage examples for android.hardware.usb UsbDevice getProductId

Introduction

In this page you can find the example usage for android.hardware.usb UsbDevice getProductId.

Prototype

public int getProductId() 

Source Link

Document

Returns a product ID for the device.

Usage

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

public void searchForUsbCamera() {
    boolean deviceFound = false;
    try {/* ww  w.  j  a v  a2s. com*/
        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.physicaroid.pocketduino.cordova.PocketDuino.java

private void getDeviceName(CallbackContext callbackContext) {
    Activity activity = cordova.getActivity();
    UsbManager mUsbManager = (UsbManager) activity.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> map = mUsbManager.getDeviceList();
    Iterator<UsbDevice> it = map.values().iterator();
    while (it.hasNext()) {
        UsbDevice device = it.next();
        // use device info
        Log.v(POCKETDUINO, "!!!--- USB Device Name ---!!!");
        Log.v(POCKETDUINO, device.getDeviceName());
        Log.v(POCKETDUINO, "!!!--- USB Device Product ID ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.getProductId()));
        Log.v(POCKETDUINO, "!!!--- USB Device Vendor ID ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.getVendorId()));
        Log.v(POCKETDUINO, "!!!--- USB Device Hash Code ---!!!");
        Log.v(POCKETDUINO, Integer.toString(device.hashCode()));
    }/*from w  w  w  . ja  v  a  2 s .  c  om*/
}

From source file:com.grupohqh.carservices.operator.ManipulateCarActivity.java

@Override
public void onResume() {
    super.onResume();
    new LoadCarBrandsAsyncTask().execute(CARBRAND_URL);
    if (useMiniMe) {
        txtStatus.setText("desconectado");
        try {/*w  w  w  . j a  va2s  . c om*/
            HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
            Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
            while (deviceIterator.hasNext()) {
                UsbDevice device = deviceIterator.next();
                if (device.getProductId() == PID && device.getVendorId() == VID)
                    if (!manager.hasPermission(device)) {
                        txtStatus.setText("sin permisos");
                        manager.requestPermission(device,
                                PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0));
                        break;
                    } else {
                        txtStatus.setText("conectado");
                    }
            }
        } catch (Exception e) {
            Log.d("USB error", e.getMessage());
        }
    }
}

From source file:fr.bmartel.android.fadecandy.service.FadecandyService.java

/**
 * initialize usb device list to request permission if not already given for already connected USB devices.
 *///  ww w.  ja  v a 2 s . com
private void initUsbDeviceList() {

    mUsbDevices.clear();

    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();

    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();

        if (device.getVendorId() == Constants.FC_VENDOR && device.getProductId() == Constants.FC_PRODUCT) {
            dispatchAttached(device);
        }
    }
}

From source file:com.ekumen.tangobot.application.MainActivity.java

/**
 * Called when permission has been granted to a device
 * It routes to the appropriate node starting code
 *///from w ww  .j  ava 2  s. co m
private void onDeviceReady(final UsbDevice device) {
    // If we got a Kobuki base, save the device pointer and unlock the latch so that the waiting
    // ROS node can be launched
    mLog.info("Connected device: vendor" + device.getVendorId() + "product: " + device.getProductId());
    if (device.getVendorId() == 1027 && device.getProductId() == 24577) {
        mUsbDevice = device;
        mUsbDeviceLatch.countDown();
    }
}

From source file:org.chromium.ChromeUsb.java

private void getDevices(CordovaArgs args, JSONObject params, final CallbackContext callbackContext)
        throws JSONException, UsbError {
    HashMap<String, UsbDevice> devices = mUsbManager.getDeviceList();
    JSONArray result = new JSONArray();
    for (UsbDevice device : devices.values()) {
        addDeviceToArray(result, device.getDeviceId(), device.getVendorId(), device.getProductId());
    }//from  w ww  .  jav  a 2s  . c om
    if (params.optBoolean("appendFakeDevice", false)) {
        addDeviceToArray(result, FakeDevice.ID, FakeDevice.VID, FakeDevice.PID);
    }
    callbackContext.success(result);
}

From source file:com.googlecode.android_scripting.facade.USBHostSerialFacade.java

/**
 * usbserialGetDeviceList: {{{1/*w  ww  .  jav  a  2  s .  c o m*/
 */
@Rpc(description = "Returns USB devices reported by USB Host API.", returns = "Map of id and string information ',' separated")
public Map<String, String> usbserialGetDeviceList() {
    Map<String, String> ret = new HashMap<String, String>();
    Map<String, UsbDevice> map = mUsbManager.getDeviceList();
    for (Map.Entry<String, UsbDevice> entry : map.entrySet()) {
        UsbDevice dev = entry.getValue();
        String v = "[\"";
        v += dev.getDeviceName();
        v += String.format("\",\"%04X", dev.getVendorId());
        v += String.format("\",\"%04X", dev.getProductId());
        v += "\",\"" + dev.hashCode();
        v += "\"]";
        ret.put(entry.getKey(), v);
    }
    return ret;
}

From source file:org.chromium.ChromeUsb.java

private void openDevice(CordovaArgs args, JSONObject params, final CallbackContext callbackContext)
        throws JSONException, UsbError {
    // First recover the device object from Id.
    int devId = params.getInt("device");
    ConnectedDevice dev = null;/*from   www  .  jav  a  2 s  .co  m*/
    int vid = -1, pid = -1;
    {
        HashMap<String, UsbDevice> devices = mUsbManager.getDeviceList();
        UsbDevice usbDev = null;
        for (UsbDevice d : devices.values()) {
            if (d.getDeviceId() == devId) {
                usbDev = d;
                break;
            }
        }
        if (usbDev != null) {
            if (mUsbReceiver == null) {
                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) {
                                        UsbDeviceConnection usbConn = mUsbManager.openDevice(device);
                                        if (usbConn == null) {
                                            throw new UsbError(
                                                    "UsbManager.openDevice returned null opening " + device);
                                        }
                                        ConnectedDevice dev = new RealDevice(device, usbConn);
                                        int vid = device.getVendorId();
                                        int pid = device.getProductId();

                                        if (dev == null || vid < 0 || pid < 0) {
                                            throw new UsbError("Unknown device ID: " + device);
                                        }
                                        int handle = mNextConnectionId++;
                                        mConnections.put(handle, dev);
                                        JSONObject jsonHandle = new JSONObject();
                                        try {
                                            jsonHandle.put("handle", handle);
                                            jsonHandle.put("vendorId", vid);
                                            jsonHandle.put("productId", pid);
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        callbackContext.success(jsonHandle);
                                    }
                                } else {
                                    Log.d(TAG, "permission denied for device " + device);
                                }
                            }
                        }
                    }
                };

                IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
                webView.getContext().registerReceiver(mUsbReceiver, filter);
            }

            mUsbManager.requestPermission(usbDev, mPermissionIntent);
        } else if (devId == FakeDevice.ID) {
            dev = new FakeDevice();
            vid = FakeDevice.VID;
            pid = FakeDevice.PID;

            if (dev == null || vid < 0 || pid < 0) {
                throw new UsbError("Unknown device ID: " + devId);
            }
            int handle = mNextConnectionId++;
            mConnections.put(handle, dev);
            JSONObject jsonHandle = new JSONObject();
            jsonHandle.put("handle", handle);
            jsonHandle.put("vendorId", vid);
            jsonHandle.put("productId", pid);
            callbackContext.success(jsonHandle);
        }
    }
}

From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java

private UsbDevice getDeviceFromAttached() {
    debugLog("Checking all connected devices");
    for (UsbDevice connectedDevice : usbManager.getDeviceList().values()) {

        debugLog("Checking device: " + connectedDevice.getProductId() + " " + connectedDevice.getVendorId());

        if (connectedDevice.getVendorId() == gpsVendorId & connectedDevice.getProductId() == gpsProductId) {
            debugLog("Found correct device");

            return connectedDevice;
        }//  w  w w  .  j a  v  a 2 s. c o  m
    }

    return null;
}