I tried to write primitive activity to scan a USB port and display basic information for a connected device. I am particularly interested in reading the device class that I rely on the UsbDevice.getDeviceClass () method . Here's what it looks like:
HashMap<String, UsbDevice> deviceList = findUsbDevices(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); if (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); String name = device.toString(); String cls = Integer.toString(device.getDeviceClass()); displayDeviceInfo(name, cls); }
However, it does not work as expected, giving 0 for any connected device. Many other fields of the UsbDevice object, such as a subclass or protocol, are also equal to 0. How can I get a device class?
source share