Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UsbManager.getDeviceList() returns empty

Tags:

android

usb

I want to use the UsbManager API by wrote following code:

In the Activity code:

        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

        HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

        Log.d(TAG, "size =" + deviceList.size());

In the Manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

    <permission android:name="android.hardware.usb.host" >

</permission>

<uses-feature android:name="android.hardware.usb.host" android:required="true" />

I also followed this question, checked my Galaxy SII 9100G. It does have /system/etc/permissions/android.hardware.usb.host.xml, and the right permissions.

But manager.getDeviceList() always return zero, when I tried flash-driver and mouse.

Can anyone give me any suggestion?

like image 269
Bennett Ma Avatar asked Nov 03 '22 00:11

Bennett Ma


1 Answers

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

  • root device with VRoot or Baidu Root (i were used last one, because don't have any windows near me)
  • install USB Host Diagnostic
  • Start diagnosic, and after it unsuccessfully completes it request root privileges and confirm you to fix system, agree with it
  • After fix, sure VERDICT part contain line 3rd party apps - Full
  • After all i were reset my device to remove root (it's dangerous in general, and Baidu Root always request to install some bloatware)

Now this device ready to work with USB devices.

like image 58
Alexey Sviridov Avatar answered Nov 15 '22 12:11

Alexey Sviridov