Codota Logo
UsbDevice
Code IndexAdd Codota to your IDE (free)

How to use
UsbDevice
in
android.hardware.usb

Best Java code snippets using android.hardware.usb.UsbDevice (Showing top 20 results out of 369)

  • Common ways to obtain UsbDevice
private void myMethod () {
UsbDevice u =
  • Codota IconIntent intent;String name;intent.getParcelableExtra(name)
  • Codota IconIntent intent;String name;(UsbDevice) intent.getParcelableExtra(name)
  • Smart code suggestions by Codota
}
origin: fossasia/pslab-android

public CommunicationHandler(UsbManager usbManager) {
  this.mUsbManager = usbManager;
  mUsbDevice = null;
  for (final UsbDevice device : mUsbManager.getDeviceList().values()) {
    Log.d(TAG, "VID : " + device.getVendorId() + "PID : " + device.getProductId());
    if (device.getVendorId() == PSLAB_VENDOR_ID && device.getProductId() == PSLAB_PRODUCT_ID) {
      Log.d(TAG, "Found PSLAB Device");
      mUsbDevice = device;
      device_found = true;
      break;
    }
  }
  mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE];
  mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE];
}
origin: robolectric/robolectric

/**
 * Adds a USB device into available USB devices map with permission value. If the USB device
 * already exists, updates the USB device with new permission value.
 */
public void addOrUpdateUsbDevice(UsbDevice usbDevice, boolean hasPermission) {
 Preconditions.checkNotNull(usbDevice);
 Preconditions.checkNotNull(usbDevice.getDeviceName());
 usbDevices.put(usbDevice.getDeviceName(), usbDevice);
 if (hasPermission) {
  grantPermission(usbDevice);
 } else {
  revokePermission(usbDevice, RuntimeEnvironment.application.getPackageName());
 }
}
origin: square/assertj-android

public UsbDeviceAssert hasInterfaceCount(int count) {
 isNotNull();
 int actualCount = actual.getInterfaceCount();
 assertThat(actualCount) //
   .overridingErrorMessage("Expected interface count <%s> but was <%s>.", count,
     actualCount) //
   .isEqualTo(count);
 return this;
}
origin: kshoji/USB-MIDI-Driver

if (usbVendorId != -1 && device.getVendorId() != usbVendorId) {
  return false;
if (usbProductId != -1 && device.getProductId() != usbProductId) {
  return false;
if (matches(device.getDeviceClass(), device.getDeviceSubclass(), device.getDeviceProtocol())) {
  return true;
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
  UsbInterface intf = device.getInterface(i);
  if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) {
    return true;
origin: felHR85/UsbSerial

device = entry.getValue();
Log.d(TAG, String.format("USBDevice.HashMap (vid:pid) (%X:%X)-%b class:%X:%X name:%s",
    device.getVendorId(), device.getProductId(),
    UsbSerialDevice.isSupported(device),
    device.getDeviceClass(), device.getDeviceSubclass(),
    device.getDeviceName()));
int deviceVID = device.getVendorId();
int devicePID = device.getProductId();
origin: NightscoutFoundation/xDrip

static public boolean isG4Connected(Context c){
  UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
  HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
  Log.i("USB DEVICES = ", deviceList.toString());
  Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
  Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));
  while(deviceIterator.hasNext()){
    UsbDevice device = deviceIterator.next();
    if (device.getVendorId() == 8867 && device.getProductId() == 71
        && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
        && device.getDeviceProtocol() == 0){
      Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
      return true;
    }
  }
  return false;
}
origin: alt236/USB-Device-Info---Android

private void populateDataTable(LayoutInflater inflater) {
  final String vid = padLeft(Integer.toHexString(device.getVendorId()), "0", 4);
  final String pid = padLeft(Integer.toHexString(device.getProductId()), "0", 4);
  final String deviceClass = UsbConstantResolver.resolveUsbClass(device.getDeviceClass());
    viewHolder.getReportedVendor().setText(device.getManufacturerName());
    viewHolder.getReportedProduct().setText(device.getProductName());
  } else {
    viewHolder.getReportedVendor().setText(R.string.not_provided);
  for (int i = 0; i < device.getInterfaceCount(); i++) {
    iFace = device.getInterface(i);
    if (iFace != null) {
      final TableLayout bottomTable = viewHolder.getBottomTable();
    loadAsyncData(viewHolder, vid, pid, device.getManufacturerName());
  } else {
    loadAsyncData(viewHolder, vid, pid, null);
origin: fossasia/pslab-android

public void open() throws IOException {
  if (!device_found) {
    throw new IOException("Device not Connected");
  }
  mConnection = mUsbManager.openDevice(mUsbDevice);
  Log.d(TAG, "Claiming interfaces, count=" + mUsbDevice.getInterfaceCount());
  mConnection.controlTransfer(0x21, 0x22, 0x1, 0, null, 0, 0);
  mControlInterface = mUsbDevice.getInterface(0);
  Log.d(TAG, "Control interface=" + mControlInterface);
  if (!mConnection.claimInterface(mControlInterface, true)) {
    throw new IOException("Could not claim control interface.");
  }
  mControlEndpoint = mControlInterface.getEndpoint(0);
  Log.d(TAG, "Control endpoint direction: " + mControlEndpoint.getDirection());
  Log.d(TAG, "Claiming data interface.");
  mDataInterface = mUsbDevice.getInterface(1);
  Log.d(TAG, "data interface=" + mDataInterface);
  if (!mConnection.claimInterface(mDataInterface, true)) {
    throw new IOException("Could not claim data interface.");
  }
  mReadEndpoint = mDataInterface.getEndpoint(1);
  Log.d(TAG, "Read endpoint direction: " + mReadEndpoint.getDirection());
  mWriteEndpoint = mDataInterface.getEndpoint(0);
  Log.d(TAG, "Write endpoint direction: " + mWriteEndpoint.getDirection());
  connected = true;
  setBaudRate(1000000);
  //Thread.sleep(1000);
  clear();
}
origin: androidthings/sample-usbenum

/**
 * Enumerate the endpoints and interfaces on the connected device.
 *
 * @param device Device to query.
 * @return String description of the device configuration.
 */
public static String readDevice(UsbDevice device) {
  StringBuilder sb = new StringBuilder();
  sb.append("Device Name: " + device.getDeviceName() + "\n");
  sb.append(String.format(
      "Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
      nameForClass(device.getDeviceClass()),
      device.getDeviceSubclass(), device.getDeviceProtocol()));
  for (int i = 0; i < device.getInterfaceCount(); i++) {
    UsbInterface intf = device.getInterface(i);
    sb.append(String.format(Locale.US,
        "-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
        intf.getId(),
        nameForClass(intf.getInterfaceClass()),
        intf.getInterfaceSubclass(),
        intf.getInterfaceProtocol()));
    sb.append(String.format(Locale.US, "   -- Endpoint Count: %d\n",
        intf.getEndpointCount()));
  }
  return sb.toString();
}
origin: kshoji/USB-MIDI-Driver

@NonNull
@Override
public Info getDeviceInfo() {
  if (cachedInfo != null) {
    return cachedInfo;
  }
  UsbDevice usbDevice = null;
  for (final MidiInputDevice midiInputDevice : transmitters.keySet()) {
    usbDevice = midiInputDevice.getUsbDevice();
    break;
  }
  if (usbDevice == null) {
    for (final MidiOutputDevice midiOutputDevice : receivers.keySet()) {
      usbDevice = midiOutputDevice.getUsbDevice();
      break;
    }
  }
  if (usbDevice == null) {
    // XXX returns `null` information
    return cachedInfo = new Info("(null)", "(null)", "(null)", "(null)");
  }
  return cachedInfo = new Info(usbDevice.getDeviceName(), //
      String.format("vendorId: %x, productId: %x", usbDevice.getVendorId(), usbDevice.getProductId()), //
      "deviceId:" + usbDevice.getDeviceId(), //
      usbDevice.getDeviceName());
}
origin: trezor/trezor-android

static boolean deviceIsTrezor(UsbDevice usbDevice) {
  // no usable interfaces
  if (usbDevice.getInterfaceCount() <= 0) {
    return false;
  }
  // TREZOR v1
  if (usbDevice.getVendorId() == 0x534c) {
    return usbDevice.getProductId() == 0x0001;
  }
  // TREZOR v2
  if (usbDevice.getVendorId() == 0x1209) {
    return usbDevice.getProductId() == 0x53c0 || usbDevice.getProductId() == 0x53c1;
  }
  return false;
}
origin: DeviceConnect/DeviceConnect-Android

/**
 * Delete HVC-P Device.
 * @param device device
 */
public void removeUSBDevice(final UsbDevice device) {
  HVCCameraInfo camera = mServices.remove("" + device.getDeviceId() + "_" + device.getProductId() + "_" + device.getVendorId());
  if (camera != null) {
    // デバイスとの接続切断を通知.
    notifyOnDisconnected(camera);
  }
}
origin: NightscoutFoundation/xDrip

public static UsbDevice getUsbDevice(final int vendorId, final int productId, final String search) {
  final UsbManager manager = (UsbManager) xdrip.getAppContext().getSystemService(Context.USB_SERVICE);
  if (manager == null) return null;
  final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
  for (Map.Entry<String, UsbDevice> entry : deviceList.entrySet()) {
    final UsbDevice device = entry.getValue();
    if (device.getVendorId() == vendorId && device.getProductId() == productId
        && device.toString().contains(search)) {
      Log.d(TAG, "Found device: " + entry.getKey() + " " + device.toString());
      return device;
    }
  }
  return null;
}
origin: stackoverflow.com

UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
HashMap<String, UsbDevice> devicelist = usbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = devicelist.values().iterator();
while(deviceIterator.hasNext()) {
 UsbDevice usbDevice = deviceIterator.next();
 Log.i(Log_Tag, "Model     : " +usbDevice.getDeviceName());
 Log.i(Log_Tag, "Id        : " +usbDevice.getDeviceId());
}
origin: zhouzhuo810/OkUSB

UsbInterface usbInterface = mDevice.getInterface(0);
  if (mDevice.getDeviceClass() == 0x02) {
    mDeviceType = DEVICE_TYPE_0;
  } else {
      if (maxPacketSize0 == 64) {
        mDeviceType = DEVICE_TYPE_HX;
      } else if ((mDevice.getDeviceClass() == 0x00)
          || (mDevice.getDeviceClass() == 0xff)) {
        mDeviceType = DEVICE_TYPE_1;
      } else {
origin: felHR85/UsbSerial

public CH34xSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
{
  super(device, connection);
  rtsCtsEnabled = false;
  dtrDsrEnabled = false;
  mInterface = device.getInterface(iface >= 0 ? iface : 0);
}
origin: square/assertj-android

 public UsbDeviceAssert hasVendorId(int id) {
  isNotNull();
  int actualId = actual.getVendorId();
  assertThat(actualId) //
    .overridingErrorMessage("Expected vendor ID <%s> but was <%s>.", id, actualId) //
    .isEqualTo(id);
  return this;
 }
}
origin: square/assertj-android

public UsbDeviceAssert hasProductId(int id) {
 isNotNull();
 int actualId = actual.getProductId();
 assertThat(actualId) //
   .overridingErrorMessage("Expected product ID <%s> but was <%s>.", id, actualId) //
   .isEqualTo(id);
 return this;
}
origin: square/assertj-android

public UsbDeviceAssert hasDeviceId(int id) {
 isNotNull();
 int actualId = actual.getDeviceId();
 assertThat(actualId) //
   .overridingErrorMessage("Expected device id <%s> but was <%s>.", id, actualId) //
   .isEqualTo(id);
 return this;
}
origin: square/assertj-android

public UsbDeviceAssert hasDeviceClass(int value) {
 isNotNull();
 int actualValue = actual.getDeviceClass();
 assertThat(actualValue) //
   .overridingErrorMessage("Expected device class <%s> but was <%s>.", value, actualValue) //
   .isEqualTo(value);
 return this;
}
android.hardware.usbUsbDevice

Most used methods

  • getVendorId
  • getProductId
  • getDeviceName
  • getInterfaceCount
  • getInterface
  • getDeviceClass
  • getDeviceId
  • getDeviceSubclass
  • getDeviceProtocol
  • equals
  • getProductName
  • getManufacturerName
  • getProductName,
  • getManufacturerName,
  • toString,
  • getConfiguration,
  • getConfigurationCount

Popular in Java

  • Finding current android device location
  • setRequestProperty (URLConnection)
  • getApplicationContext (Context)
  • requestLocationUpdates (LocationManager)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • PriorityQueue (java.util)
    An unbounded priority Queue based on a priority heap. The elements of the priority queue are ordered
  • TreeMap (java.util)
    A Red-Black tree based NavigableMap implementation. The map is sorted according to the Comparable of
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now