felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.78k stars 581 forks source link

getDeviceList empty #349

Open aprldntm1234 opened 2 years ago

aprldntm1234 commented 2 years ago

I developed a program using this library. HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList(); Log.d("usbDevices_log", usbDevices.toString());

where usbManager.getDeviceList(); When I output the value as log, it came out empty.

Is there no solution? For reference, the current version is 5.1.1 Lollipop.

image

davdavcoco commented 1 year ago

hey, did your problem solved?

eclectice commented 1 year ago

The [UsbManager.getDeviceList()](https://developer.android.com/reference/android/hardware/usb/UsbManager#getDeviceList()) method is a standard USB-Host method in Android. So it's not the felHR85-UsbSerial library's fault.

Returns a HashMap containing all USB devices currently attached. USB device name is the key for the returned HashMap. The result will be empty if no devices are attached, or if USB host mode is inactive or unsupported. Requires the PackageManager#FEATURE_USB_HOST feature which can be detected using PackageManager.hasSystemFeature(String).

Did you use an Android emulator that Android Studio provided to run your app? In that case, It is not supported.

https://developer.android.com/studio/run/advanced-emulator-usage#limitations

Some non-standard Android devices require OTG support to be enabled (in their setting) before using any USB serial adapter.

If you don't attach any USB serial adapter, the UsbManager.getDeviceList() method will return an empty list.

Other than that, try to check USB Host support for your hardware device with this app from Google Play Store: https://play.google.com/store/apps/details?id=eu.chainfire.usbhostdiagnostics