I want to use the UsbManager
API by wrote following code:
In the Activity code:
UsbManager manager = (UsbManager) getSystemServi
I have had this problem with a Huawei Mate 20 Pro running Android Pie. Same programs work perfectly on Android 5 or 7 devices. There is some evidence this is an Android Pie problem: https://issuetracker.google.com/issues/121435921
There isn't common answer for your question. It heavily depend on your device. Emulator don't support USB host at all, some devices need root to do it, some devices has right USB host support out of the box.
EDIT
I'm recently finish my own investigation for this problem for device TF-MID1007G. May be this will helpful for someone later. There is great app to perform diagnostic of USB host abilities of device - USB Host Diagnostic (btw many thanks to author, you really save my day ). This app show verdict about usb host support of device, in my case it was usb host supported by kernel, but restricted for third party apps. Fortunately this app can also (on rooted devices only) fix your device system to add ability work with usb host. This fix remains even after reset device. After this fix my app can enumerate usb host devices, request permission and so on, as described in standard android API. So short list of action to enable normal usb host supporting on this device
Now this device ready to work with USB devices.
This code works fine for me. Although your code looks similar you can recheck.
UsbManager usbManager = (UsbManager) getSystemService(USB_SERVICE);
HashMap<String, UsbDevice> map = usbManager.getDeviceList();
Iterator<UsbDevice> it = map.values().iterator();
while(it.hasNext()) {
UsbDevice device = it.next();
// use device info
}
Probably you are trying to run through android emulator but.....according to Android specs for the emulator : http://developer.android.com/tools/devices/emulator.html#limitations
The functional limitations of the emulator include:
No support for USB connections
So, only with real device you can test UsbManager