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:com.noisepages.nettoyeur.usb.DeviceInfo.java

/**
 * Synchronously retrieves device info from the web. This method must not be invoked on the main
 * thread as it performs blocking network operations that may cause the app to become
 * unresponsive.//from   ww w . j  a  va 2s. c  o  m
 * 
 * Requires android.permission.INTERNET.
 * 
 * @param device for which to retrieve information
 * @return device info, or null on failure
 */
public static DeviceInfo retrieveDeviceInfo(UsbDevice device) {
    DeviceInfo info = null;
    try {
        info = retrieveDeviceInfo(device.getVendorId(), device.getProductId());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return info;
}

From source file:com.noisepages.nettoyeur.usb.DeviceInfo.java

/**
 * Constructor for default instances of DeviceInfo, populated with numerical IDs rather than
 * human-readable names.//www.  j  a  va 2s  .  c o m
 */
public DeviceInfo(UsbDevice device) {
    this(asFourDigitHex(device.getVendorId()), asFourDigitHex(device.getProductId()));
}

From source file:org.ros.android.android_acm_serial.AcmDeviceActivity.java

protected Collection<UsbDevice> getUsbDevices(int vendorId, int productId) {
    Collection<UsbDevice> allDevices = usbManager.getDeviceList().values();
    Collection<UsbDevice> matchingDevices = Lists.newArrayList();
    for (UsbDevice device : allDevices) {
        if (device.getVendorId() == vendorId && device.getProductId() == productId) {
            matchingDevices.add(device);
        }//  w w w .j a v  a 2  s.co m
    }
    return matchingDevices;
}

From source file:info.martinmarinov.dvbservice.DeviceChooserActivity.java

private void handleException(DvbException e) {
    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
    Collection<UsbDevice> availableDevices = manager.getDeviceList().values();
    int[] productIds = new int[availableDevices.size()];
    int[] vendorIds = new int[availableDevices.size()];

    int id = 0;/*from  www  . ja va  2s.  co  m*/
    for (UsbDevice usbDevice : availableDevices) {
        productIds[id] = usbDevice.getProductId();
        vendorIds[id] = usbDevice.getVendorId();
        id++;
    }

    response.putExtra(CONTRACT_ERROR_CODE, e.getErrorCode().name());
    response.putExtra(CONTRACT_RAW_TRACE, StackTraceSerializer.serialize(e));
    response.putExtra(CONTRACT_USB_PRODUCT_IDS, productIds);
    response.putExtra(CONTRACT_USB_VENDOR_IDS, vendorIds);

    finishWith(RESULT_ERROR);
}

From source file:org.deviceconnect.android.deviceplugin.fabo.setting.fragment.FaBoConnectFragment.java

@Override
public void onResume() {
    super.onResume();

    // USB????Broadcast Receiver.
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(FaBoConst.DEVICE_TO_ARDUINO_OPEN_USB_RESULT);
    mIntentFilter.addAction(FaBoConst.DEVICE_TO_ARDUINO_CHECK_USB_RESULT);
    mIntentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    mContext.registerReceiver(mUSBResultEvent, mIntentFilter);

    // Arduino Uno???.
    Intent intent = new Intent(FaBoConst.DEVICE_TO_ARDUINO_CHECK_USB);
    mContext.sendBroadcast(intent);/*  w ww  .j av a  2 s. c  om*/

    // USB???.
    UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

    for (UsbDevice device : deviceList.values()) {
        if (device.getVendorId() == 10755) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewCommment.setText(R.string.arduinoorg_find);
                    mOutputButton.setEnabled(false);
                }
            });
        } else if (device.getVendorId() == 9025) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewCommment.setText(R.string.arduinocc_find);
                    mOutputButton.setEnabled(true);
                }
            });
            break;
        }
    }
}

From source file:com.swiftnav.piksidroid.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    this.setupUI();

    UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    registerReceiver(mUsbReceiver, filter);

    filter = new IntentFilter(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbReceiverDisconnect, filter);

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

    for (UsbDevice device : deviceList.values()) {
        if ((device.getVendorId() == Utils.PIKSI_VID) && (device.getProductId() == Utils.PIKSI_PID))
            if (!mUsbManager.hasPermission(device)) {
                mUsbManager.requestPermission(device, mPermissionIntent);
            } else {
                ((EditText) findViewById(R.id.console)).setText("");
                piksiConnected(device);/*w w w  .  jav a  2  s .  com*/
            }
    }
}

From source file:com.numato.usbgenie.ui.MainActivity.java

/**
 * Using the Context.USB_SERVICE it enumreates all the NUMATOLAB devices
 *
 * @return the number of devices enumerated
 *//*from  ww w  .j a v a  2  s.c  om*/
private int enumerateDevices() {
    int index = 0;

    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
    ArrayList<UsbDevice> cdcAcmDevices = CdcAcmDriver.ListDevices(manager);

    mDevicesManager.clearDevices();

    ArrayList<Integer> supportedDevices = NumatoUSBDevice.GetSupportedProductIds();

    if (!cdcAcmDevices.isEmpty()) {
        for (UsbDevice cdcAcmDevice : cdcAcmDevices) {
            int vendorId = cdcAcmDevice.getVendorId();

            if (vendorId == NumatoUSBDevice.VID_NUMATOLAB
                    && supportedDevices.contains(cdcAcmDevice.getProductId())) {
                mDevicesManager.addDevice(new NumatoUSBDevice(index, cdcAcmDevice, manager));
                index++;
            }
        }
    }

    return index;
}

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

public UsbDevice findUsbDevice() {

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

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

    mLogger.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 (dev.getVendorId() == getVid() && dev.getProductId() == getPid()) {
            usbDevice = dev;
            msg += " <- using this one.";
        }

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

From source file:org.deviceconnect.android.deviceplugin.fabo.setting.fragment.FaBoFirmwareFragment.java

@Override
public void onResume() {
    super.onResume();

    // SerialPort??
    mStkWriter = new StkWriter(getActivity().getBaseContext());
    mStkWriter.setListener(this);

    // USB???.//from www .  jav  a 2  s  .c o m
    UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

    for (UsbDevice device : deviceList.values()) {
        if (device.getVendorId() == 10755) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewCommment.setText(R.string.arduinoorg_find);
                    mButtonConnect.setEnabled(false);
                    mButtonSend.setVisibility(Button.INVISIBLE);
                    mButtonBack.setVisibility(Button.INVISIBLE);
                }
            });
        } else if (device.getVendorId() == 9025) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewCommment.setText(R.string.arduinocc_find_sendfirmware);
                    mButtonConnect.setEnabled(true);
                    mButtonSend.setVisibility(Button.INVISIBLE);
                    mButtonBack.setVisibility(Button.INVISIBLE);
                }
            });
            break;
        }
    }
}

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

public void connect(UsbDevice usbDevice) {
    if (usbDevice == null) {
        mLogger.log("Device not found.");
        return;//from  ww  w.  j  ava  2 s  .  c om
    }

    if (usbDevice.getProductId() != getPid() || usbDevice.getVendorId() != getVid()) {
        mLogger.log("Not a valid device");
        return;
    }

    mUsbDevice = usbDevice;

    // Request permission
    // This displays a dialog asking user for permission to use the device.
    // No dialog is displayed if the permission was already given before or the app started as a
    // result of intent filter when the device was plugged in.

    PendingIntent permissionIntent = PendingIntent.getBroadcast(mContext, 0,
            new Intent(getUsbPermissionResponseIntent()), 0);
    mContext.registerReceiver(respondToUsbPermission, new IntentFilter(getUsbPermissionResponseIntent()));
    mLogger.log("Requesting permission for USB device.");
    mUsbManager.requestPermission(mUsbDevice, permissionIntent);
}