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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With