Android USB 主机和隐藏设备 [英] Android USB host and hidden devices
问题描述
我正在开发一个 Android 应用程序,我必须在其中与 USB 设备进行通信.我尝试在我的应用中使用标准的 google API,但设备列表始终为空.
I am developing an Android application in which I have to communicate to an USB device. I tried to use standart google API in my app, but list of devices is allways empty.
如果我将 USB 设备信息与 google api 一起使用,则情况相同.google api搜索到的设备列表为空,
Same things if i use USB device info with google api. List of devices searched by google api is empty,
lsusb 给出以下结果:
lsusb gives following results:
Bus 001 Device 001: ID 1d6b:0001
Bus 002 Device 001: ID 1d6b:0002
Bus 003 Device 001: ID 1d6b:0001
Bus 002 Device 002: ID 2226:0014
我的设备是 2226:0014
my device is 2226:0014
日食日志:
I/USB3G(92): event { 'add', '/devices/platform/sw-ehci.1/usb2/2-1', 'usb', '', 189, 133 }
I/USB3G(92): path : '/sys/devices/platform/sw-ehci.1/usb2/2-1'
I/USB3G(92): VID :size 5,vid_path '/sys/devices/platform/sw-ehci.1/usb2/2-1/idVendor',VID '2226
I/USB3G(92): '.
I/USB3G(92): PID :size 5,Pid_path '/sys/devices/platform/sw-ehci.1/usb2/2-1/idProduct',PID '0014
I/USB3G(92): '.
I/USB3G(92): cmd=/system/etc/usb_modeswitch.sh /system/etc/usb_modeswitch.d/2226_0014 &,
I/USB3G(92): excute ret : 0,err:No such file or directory
如果我插入诸如 rs232 适配器、蓝牙加密狗之类的设备,则没有任何反应,API 和 lsusb 也没有任何结果.
If i plug in devices like rs232 adapters, bluetooth dongle, nothing happens,and there is no any result from API and lsusb.
设备的协议基于ezusb库.安卓版本:4.0.3内核版本:3.0.8固件版本:crash_evb-eng 4.0.3 IMLK74k 20120330
Prtocol of a device is based on ezusb library. Android v.: 4.0.3 kernel v.: 3.0.8 firmware build: crane_evb-eng 4.0.3 IMLK74k 20120330
有没有办法通过 API 访问隐藏的 USB 设备,或者我应该通过编写驱动程序并将其修补到固件中来实现对该设备的支持?
Is there are any way to access hidden USB devices via API, or should i implement support of this device by writing driver and patching it into the firmware?
更新:即使我在 *system/etc/usb_modeswitch.d/* 中创建了名称为 2226_0014 的信息文件包含
UPDATE: even if i create info file in *system/etc/usb_modeswitch.d/* with name 2226_0014 containing
DefaultVendor= 0x2226
DefaultProduct=0x0014
TargetVendor= 0x2226
TargetProductList="0014"
MessageEndpoint="0x00"
NeedResponse=1
CheckSuccess=20
我得到同样的错误:没有这样的文件或目录"
i get the same error: "No such file or directory"
推荐答案
要启用 USB 主机 API 支持,您应该添加一个名为
的文件android.hardware.usb.host.xml并包含以下几行:
To enable USB host API support you should add a file named
android.hardware.usb.host.xml
and containing the following lines:
<permissions>
<feature name="android.hardware.usb.host"/>
</permissions>
进入文件夹
/system/etc/permissions
在该文件夹中找到名为
handheld_core_hardware.xml or tablet_core_hardware.xml
并添加
<feature name="android.hardware.usb.host" />
进入
部分.
重新启动您的设备.USB 主机 api 应该可以工作.
Reboot your device. Usb host api should work.
在 CUBE U30GT 和 android 4 上测试.
Tested on CUBE U30GT with android 4.
这篇关于Android USB 主机和隐藏设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!