UsbManager.getDeviceList() 返回空 [英] UsbManager.getDeviceList() returns empty

查看:52
本文介绍了UsbManager.getDeviceList() 返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过编写以下代码来使用 UsbManager API:

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

在活动代码中:

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

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

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

在清单中:

<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" />

我也关注了这个问题,检查了我的 Galaxy SII 9100G.它确实有 /system/etc/permissions/android.hardware.usb.host.xml 和正确的权限.

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.

但是 manager.getDeviceList() 总是返回零,当我尝试闪存驱动程序和鼠标时.

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

谁能给我任何建议?

推荐答案

您的问题没有统一的答案.这在很大程度上取决于您的设备.模拟器根本不支持 USB 主机,有些设备需要 root 才能做到,有些设备开箱即用具有正确的 USB 主机支持.

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.

编辑

我最近完成了对设备 TF-MID1007G 的这个问题的调查.可能这会对以后的人有所帮助.有很棒的应用程序可以诊断设备的 USB 主机功能 - USB主机诊断(顺便说一句,非常感谢作者,你真的拯救了我的一天).这个应用程序显示了关于设备的 USB 主机支持的判断,在我的例子中它是内核支持的 USB 主机,但限制第三方应用程序.幸运的是,这个应用程序还可以(仅在有 root 权限的设备上)修复您的设备系统以添加与 USB 主机一起工作的能力.即使在重置设备后,此修复程序仍然存在.在此修复后,我的应用程序可以枚举 USB 主机设备、请求权限等,如标准 android API 中所述.在此设备上启用正常 USB 主机支持的简短操作列表

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

  • 使用 VRoot 或百度 Root 的 root 设备(我用的是最后一个,因为我附近没有任何窗口)
  • 安装USB 主机诊断
  • 开始诊断,未成功完成后请求root权限并确认修复系统,同意
  • 修复后,确定 VERDICT 部分包含第 3 行应用程序 - 完整
  • 毕竟我重置了我的设备以删除 root(这通常很危险,而且百度 Root 总是要求安装一些英国媒体报道)

现在此设备已准备好与 USB 设备配合使用.

Now this device ready to work with USB devices.

这篇关于UsbManager.getDeviceList() 返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆