List of usage examples for android.hardware.usb UsbDevice getProductId
public int getProductId()
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 w ww . ja v a2s. c om * * 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.//from ww w . j a v a2 s. c o m */ public DeviceInfo(UsbDevice device) { this(asFourDigitHex(device.getVendorId()), asFourDigitHex(device.getProductId())); }
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;/* ww w .ja v a 2 s . c om*/ 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.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 . ja va 2 s . c om } return matchingDevices; }
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 a v a 2 s .c o m*/ } 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); }
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);/*from w ww . java 2s . com*/ } } }
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 w w . j av a 2 s.co 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.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; }/* ww w .ja 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 {// www. j a va 2s. com 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.numato.usbgenie.ui.MainActivity.java
/** * Using the Context.USB_SERVICE it enumreates all the NUMATOLAB devices * * @return the number of devices enumerated *///w ww .ja va 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; }