将 USB 设备连接到 Android 模拟器?

Connect USB device to Android Emulator?(将 USB 设备连接到 Android 模拟器?)

本文介绍了将 USB 设备连接到 Android 模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在研究 Android 3.1+ 及其读取/写入连接到 OTG/主机端口的 USB 设备的能力.

We've been looking into Android 3.1+ and its ability to read/write to USB devices connected to the OTG/Host port.

我找到了一些代码示例,可让我检测和读取/写入 USB HID 设备,但目前,我根本没有可部署和远程调试的物理 3.1+ 兼容设备.

I've found some code examples that allow me to detect and read/write to a USB HID device, but at the moment, I simply don't have a physical 3.1+ compatible device to deploy and remotely debug on.

有谁知道我如何通过 PC/Eclipse 将我的 HID 设备连接到模拟器,以便应用程序可以检测设备并读取/写入设备?

Does anyone know how I can attach my HID device to the emulator, via the PC/Eclipse so the app can detect and read/write to/from the device?

我已经尝试列出当前连接的 USB 设备,但它没有显示,正如您无疑猜到的那样.

I've tried listing the currently connected USB Devices but it shows none, as you'd no doubt guess.

有什么想法吗?

干杯

推荐答案

Android模拟器基于QEMU.即使模拟器版本如此古老,似乎也支持从主机传递 USB 设备.不过,它似乎不适用于 ARM 设备,模拟的 ARM 机器没有 USB 控制器.(我已经尝试为基于 Linux 3.4 的 goldfish_armv7 内核启用所有 USB 主机控制器,但运气不好.默认的模拟器 goldfish_armv7 内核甚至没有启用 Host USB.)

The Android emulator is based on QEMU. Even if the emulator version is so ancient, there appears to be support for passing USB devices from the host. It does not seem to be available for ARM devices though, the emulated ARM machine does not have a USB controller. (I have already tried enabling all USB host controllers for the goldfish_armv7 kernel based on Linux 3.4, without luck. The default emulator goldfish_armv7 kernel does not even have Host USB enabled.)

如果你不限于ARM并且可以使用x86,那么我建议查看http://www.android-x86.org/,它的图像可以与标准的QEMU i386(或x86_64) 机器.通过在 Linux 上使用 KVM 扩展,这也会产生更好的性能.

If you are not limited to ARM and can use x86, then I suggest to check out http://www.android-x86.org/, its images can be used with a standard QEMU i386 (or x86_64) machine. This also yields better performance by using the KVM extension on Linux.

要通过供应商 ID 1234 和设备 ID abcd 的 USB 设备,您可以运行模拟器命令:

To passthrough a USB device with of vendor ID 1234 and device ID abcd, you can run the emulator command:

emulator -avd x86-machine -qemu -usb -usbdevice host:1234:abcd

或者,当使用 QEMU 时:

Or, when using QEMU:

qemu-system-i386 -m 1G -cdrom android-x86.iso -usb -usbdevice host:1234:abcd

您将需要 /dev/bus/usb/XXX/YYY 的读/写权限,为此您可以创建一个 udev 规则,例如:

You will need read/write permissions for /dev/bus/usb/XXX/YYY, for that you can create a udev rule such as:

SUBSYSTEM!="usb", GOTO="end_skip_usb"
ATTRS{idVendor}=="1234", ATTRS{idProduct}=="abcd", TAG+="uaccess"
LABEL="end_skip_usb"

现在,插入 USB 设备后,您的模拟器应该会识别 USB 设备.这是针对使用 Android x86 4.3 映像的 Linux 安装进行测试的.

Now, upon insertion of the USB device, your emulator should recognize a USB device. This is tested for a Linux installation with a Android x86 4.3 image.

这篇关于将 USB 设备连接到 Android 模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将 USB 设备连接到 Android 模拟器?

基础教程推荐