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

发布于 2024-12-12 03:51:08 字数 279 浏览 0 评论 0原文

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

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

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

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

有什么想法吗?

干杯

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

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.

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?

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

Any ideas?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

变身佩奇 2024-12-19 03:51:08

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

如果您不限于ARM并且可以使用x86,那么我建议查看 http://www.android-x86.org/,其图像可以是与标准 QEMU i386(或 x86_64)机器一起使用。通过在 Linux 上使用 KVM 扩展,还可以获得更好的性能。

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

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

或者,在使用 QEMU 时:

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

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

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 安装进行的测试。

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.)

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.

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

Or, when using QEMU:

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

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"

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.

罗罗贝儿 2024-12-19 03:51:08

据我所知这是不可能的。 Android模拟器并不能模拟真实设备中存在的许多东西...但这让我想起了尝试通过蓝牙运行 ADB

这不是对您的问题的直接肯定答案,但也许它可以帮助您像我一样找到解决方法:在物理 x86 上网本(双引导)上安装“模拟器”并使用 我的帖子来完成您尝试通过 WiFi 或蓝牙完成的任务。

希望这有帮助。

AFAIK this isn't possible. Android emulators do not emulate many things that exist in real devices... but this reminds me of an attempt to run ADB over Bluetooth.

This isn't a direct positive answer to your question but perhaps it can help you find a workaround the way I did: Install an "emulator" on a physical x86 netbook (dual-boot) and use the links referred to in my posts to accomplish what you are trying to do via WiFi or Bluetooth.

Hope this helps.

寻找一个思念的角度 2024-12-19 03:51:08

使用此图片在virtualBox或vm播放器上创建android虚拟机。

连接USB并使用ADB connect(您的设备IP)与Eclipse连接。

在此处输入图像描述

Create android Virtual Machine on virtualBox or vm player with this image.

Connect USB and connect with Eclipse using ADB connect (your device IP).

enter image description here

如果没有 2024-12-19 03:51:08

使用来自 此处的镜像 android-x86-4.0-r1-eeepc.iso 在带有 Windows 7 主机的 virtualbox 中安装了 android guest (因为我公司的计算机锁定了 BIOS,并且我无法启用 vt-x 仿真,所以我必须安装 4.4 之前的版本)。然后插上U盘,在Virtualbox Manager中打开虚拟机-设置-USB,点击右侧第二个带有加号的图标,选择U盘。然后 Virtualbox 安装 USB 驱动器的驱动程序。完成后,启动 android VM。启动OpenManager,进入mnt/USB,U盘的文件就在那里!

Installed android guest in virtualbox with Windows 7 host using image android-x86-4.0-r1-eeepc.iso from here (because my company's computer locked bios and I couldn't enable the vt-x emulation I had to install a version prior to 4.4). Then pluged in a usb drive, opened VM - Settings - USB in Virtualbox Manager, clicked the second icon on the right with a plus sign on it, chose the usb drive. Virtualbox then installed driver for the USB drive. After it finished, booted the android VM. Started OpenManager, went to mnt/USB, and files of the usb drive were there!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文