Example usage for android.hardware.usb UsbDevice getVendorId

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

Introduction

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

Prototype

public int getVendorId() 

Source Link

Document

Returns a vendor ID for the device.

Usage

From source file:org.chromium.latency.walt.BaseUsbConnection.java

public UsbDevice findUsbDevice() {

    logger.log(String.format("Looking for TeensyUSB VID=0x%x PID=0x%x", getVid(), getPid()));

    HashMap<String, UsbDevice> deviceHash = usbManager.getDeviceList();
    if (deviceHash.size() == 0) {
        logger.log("No connected USB devices found");
        return null;
    }//from  w w  w  .  j  a v  a 2  s . c o m

    logger.log("Found " + deviceHash.size() + " connected USB devices:");

    UsbDevice usbDevice = null;

    for (String key : deviceHash.keySet()) {

        UsbDevice dev = deviceHash.get(key);

        String msg = String.format(Locale.US, "USB Device: %s, VID:PID - %x:%x, %d interfaces", key,
                dev.getVendorId(), dev.getProductId(), dev.getInterfaceCount());

        if (isCompatibleUsbDevice(dev)) {
            usbDevice = dev;
            msg = "Using " + msg;
        } else {
            msg = "Skipping " + msg;
        }

        logger.log(msg);
    }
    return usbDevice;
}

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

@Override
public void onResume() {
    super.onResume();
    etSerialNumber.setText("");
    etLicensePlate.setText("");
    etTag.setText("");
    if (useMiniMe) {
        etEpc.setText("");
        txtStatus.setText("desconectado");
        try {//from ww  w  . j a v  a 2  s.  co  m
            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:com.dslr.dashboard.PtpService.java

public void searchForUsbCamera() {
    boolean deviceFound = false;
    try {//from   w  w  w.j  av a 2s .c om
        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:fr.bmartel.android.fadecandy.service.FadecandyService.java

/**
 * initialize usb device list to request permission if not already given for already connected USB devices.
 *///from ww w.  j a  v  a2  s.  c  o m
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.grupohqh.carservices.operator.ManipulateCarActivity.java

@Override
public void onResume() {
    super.onResume();
    new LoadCarBrandsAsyncTask().execute(CARBRAND_URL);
    if (useMiniMe) {
        txtStatus.setText("desconectado");
        try {//from  w  ww  .j  av  a 2 s . c o  m
            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: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  w w .  ja v a 2s  . com
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());
    }/*  w w w  . j  av  a  2s.  c  om*/
    if (params.optBoolean("appendFakeDevice", false)) {
        addDeviceToArray(result, FakeDevice.ID, FakeDevice.VID, FakeDevice.PID);
    }
    callbackContext.success(result);
}

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 ww w  .j a  va  2 s.  c om*/
}

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

/**
 * usbserialGetDeviceList: {{{1//from w ww. j a va  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   w  w  w  .  j  a va  2s  .  c  o 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);
        }
    }
}