Reputation: 6620
I have a USB device and I want to know how I can identify "vendor name" and "device name" from vendorID and DeviceID.
And the Device name I get from USBManagers' DeviceList Hashmap does not look valid.
Finally what I want is something like this:
(Silicon - Power 8GB)
Upvotes: 2
Views: 4181
Reputation: 153
In API 21 these methods were added. It's as simple as here:
UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
if (usbManager != null) {
HashMap<String, UsbDevice> devices = usbManager.getDeviceList();
for (String key: devices.keySet()) {
Log.d(TAG, "Device Name: " + devices.get(key).getDeviceName());
Log.d(TAG, "Manufacturer Name: " + devices.get(key).getManufacturerName());
Log.d(TAG, "Product Name: " + devices.get(key).getProductName());
}
}
You could filter by vendorId and print it too.
Upvotes: 2
Reputation: 25793
You can get VendorId
and ProductId
from:
UsbDevice.getVendorId();
UsbDevice.getProductId();
You need to convert the int values to hexadecimal and compare them against a list of vendor ids/ product ids.
You can find this list here.
I'll leave the parsing to you, but it's pretty straightforward. You can find the structure at the top of the file:
# Syntax:
# vendor vendor_name
# device device_name <-- single tab
# interface interface_name <-- two tabs
Upvotes: 5