Android USB 主机和隐藏设备

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11183792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:14:49  来源:igfitidea点击:

Android USB host and hidden devices

androidapiusbhost

提问by Alexey.Shilenkov

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.

我正在开发一个 Android 应用程序,我必须在其中与 USB 设备进行通信。我试图在我的应用程序中使用标准的 google API,但设备列表始终为空。

Same things if i use USB device info with google api. List of devices searched by google api is empty,

如果我将 USB 设备信息与 google api 一起使用,则情况相同。google api 搜索到的设备列表为空,

lsusb gives following results:

lsusb 给出以下结果:

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

my device is 2226:0014

我的设备是 2226:0014

log of eclipse:

日食日志:

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

If i plug in devices like rs232 adapters, bluetooth dongle, nothing happens,and there is no any result from API and lsusb.

如果我插入诸如 rs232 适配器、蓝牙加密狗之类的设备,则没有任何反应,API 和 lsusb 也没有任何结果。

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

设备的协议基于ezusb 库。Android v.: 4.0.3 内核 v.: 3.0.8 固件版本:crane_evb-eng 4.0.3 IMLK74k 20120330

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?

有没有办法通过 API 访问隐藏的 USB 设备,或者我应该通过编写驱动程序并将其修补到固件中来实现对该设备的支持?

UPDATE: even if i create info file in *system/etc/usb_modeswitch.d/* with name 2226_0014 containing

更新:即使我在 *system/etc/usb_modeswitch.d/* 中创建信息文件,名称为 2226_0014

DefaultVendor= 0x2226
DefaultProduct=0x0014
TargetVendor=  0x2226
TargetProductList="0014"
MessageEndpoint="0x00"
NeedResponse=1
CheckSuccess=20

i get the same error: "No such file or directory"

我收到同样的错误:“没有这样的文件或目录”

回答by Greg-q

To enable USB host API support you should add a file named
android.hardware.usb.host.xmland containing the following lines:

要启用 USB 主机 API 支持,您应该添加一个名为
android.hardware.usb.host.xml并包含以下行的文件:

<permissions>
 <feature name="android.hardware.usb.host"/>
</permissions>

into folder

放入文件夹

/system/etc/permissions

in that folder find file named

在该文件夹中找到名为

handheld_core_hardware.xml or tablet_core_hardware.xml 

and add

并添加

<feature name="android.hardware.usb.host" />

into <permissions>section.

进入<permissions>部分。

Reboot your device. Usb host api should work.

重新启动您的设备。USB 主机 api 应该可以工作。

Tested on CUBE U30GT with android 4.

在 CUBE U30GT 上用安卓 4 测试。

回答by markjuggles

Excellent! This worked on my Envizen V700NA running Android 4.0.4.

优秀!这适用于我的运行 Android 4.0.4 的 Envizen V700NA。

Minor Typo: <feature name="android.hardware.usb.host">

小错别字: <feature name="android.hardware.usb.host">

Should be: <feature name="android.hardware.usb.host"/>

应该: <feature name="android.hardware.usb.host"/>

Procedure:

程序:

  1. adb pull /system/etc/permissions/tablet_core_hardware.xml
  2. Update that file and create android.hardware.usb.host.xml as specified by Greg-q.
  3. adb push android.hardware.usb.host.xml /system/etc/permissions
  4. adb push tablet_core_hardware.xml /system/etc/permissions
  5. Reboot.
  1. adb pull /system/etc/permissions/tablet_core_hardware.xml
  2. 更新该文件并创建 Greg-q 指定的 android.hardware.usb.host.xml。
  3. adb 推送 android.hardware.usb.host.xml /system/etc/permissions
  4. adb push tablet_core_hardware.xml /system/etc/permissions
  5. 重启。

回答by mahesh

Worked like a charm on a micromax A120 canvas 2 phone (kitkat 4.4.2). now i can control my Arduino! i used busybox tools to do all the command line work (otherwise chmod wouldn't work). my steps (perhaps some were not required):

在 micromax A120 帆布 2 手机(kitkat 4.4.2)上工作就像一个魅力。现在我可以控制我的Arduino了!我使用 busybox 工具来完成所有的命令行工作(否则 chmod 将无法工作)。我的步骤(也许有些不是必需的):

(0) install PDAnet drivers (http://pdanet.co/a/) on my Windows 8 computer. (1) root the phone using Vroot (now called iRoot) at http://www.mgyun.com/m/en. Very simple, only catch is that the su grant/deny page is partly in chinese, no big deal. (2) install busybox and Hymanpal's Android-Terminal-Emulator (see github https://github.com/Hymanpal/Android-Terminal-Emulatoror play store https://play.google.com/store/apps/details?id=Hymanpal.androidterm&hl=en)

(0)在我的 Windows 8 计算机上安装 PDAnet 驱动程序 ( http://pdanet.co/a/)。(1) 在http://www.mgyun.com/m/en使用 Vroot(现在称为 iRoot)对手机进行 root 。很简单,唯一的问题是 su grant/deny 页面部分是中文的,没什么大不了的。(2)安装busybox和Hymanpal的Android-Terminal-Emulator(见github https://github.com/Hymanpal/Android-Terminal-Emulator或play store https://play.google.com/store/apps/details?id =Hymanpal.androidterm&hl=en)

(3) open a terminal window and become the superuser:

(3) 打开终端窗口并成为超级用户:

# su

(4) the file system may be read-only, so you might have to remount it:

(4) 文件系统可能是只读的,所以你可能需要重新挂载它:

# mount -o rw,remount -t yaffs2 /

or

或者

# mount -o rw,remount -t rootfs /

or

或者

# mount -o rw,remount -t rootfs rootfs /system

see http://www.pocketmagic.net/write-on-the-android-read-only-file-system/also, see Android 2.3 : Read-Only file system stuckalso, https://ckirbach.wordpress.com/2012/11/27/how-to-remount-system-as-read-write-in-android/

参见http://www.pocketmagic.net/write-on-the-android-read-only-file-system/,也参见Android 2.3:只读文件系统卡住了https://ckirbach.wordpress.com /2012/11/27/how-to-remount-system-as-read-write-in-android/

(5) make default.prop read/write:

(5) 使 default.prop 读/写:

chmod 666 /default.prop

(6) edit /default.prop, make the following changes:

(6) 编辑/default.prop,做如下修改:

ro.secure=0
ro.debuggable=1
persist.service.adb.enable=1

see https://android.stackexchange.com/questions/28653/obtaining-root-by-modifying-default-propro-secureor http://bclary.com/blog/2014/04/14/splitting-and-packing-android-boot-images/

参见https://android.stackexchange.com/questions/28653/obtaining-root-by-modifying-default-propro-securehttp://bclary.com/blog/2014/04/14/splitting-and-packing -android-boot-images/

Finally, just for completeness, as the answer above says (https://stackoverflow.com/a/11992683/979369):

最后,只是为了完整性,正如上面的答案所说(https://stackoverflow.com/a/11992683/979369):

(7) To enable USB host API support you should add a file named android.hardware.usb.host.xml and containing the following lines:

(7) 要启用 USB 主机 API 支持,您应该添加一个名为 android.hardware.usb.host.xml 并包含以下行的文件:

<permissions>
 <feature name="android.hardware.usb.host"/>
</permissions>

into folder

放入文件夹

/system/etc/permissions

in that folder find file named

在该文件夹中找到名为

handheld_core_hardware.xml or tablet_core_hardware.xml 

and add

并添加

<feature name="android.hardware.usb.host" />

into section.

进入部分。

(8) Reboot your device. Usb host api should work.

(8) 重新启动您的设备。USB 主机 api 应该可以工作。

回答by Marco

i've used adb on MK809, Android 4.1 Jelly Bean, and the command are:

我在 MK809、Android 4.1 Jelly Bean 上使用了 adb,命令是:

adb remount /../../file.xml rw adb push...

adb 重新挂载 /../../file.xml rw adb 推送...

with normal command i'vent permission and the file is read only

使用普通命令我发泄权限并且文件是只读的

Sorry for my bad english :P

对不起我的英语不好:P