作为配件的 Android 设备 [英] Android device acting as an accessory

查看:33
本文介绍了作为配件的 Android 设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个 Android 设备,我想用 USB OTG 电缆连接它们并在两个设备之间进行来回通信.据我了解,一台 Android 设备将充当 USB 主机(运行 4.4 的 Nexus 7),而另一台 Android 设备将充当 USB 配件(运行 4.2.2 的 Galaxy Nexus).我试过在谷歌上搜索答案,但我似乎只能找到解释如何将 Android 设备连接到 USB 配件(如 USB 鼠标或键盘)的文章,而不是如何将 Android 设备视为 USB 配件本身.

I have 2 Android devices, which I would like to connect with a USB OTG cable and have back-and-forth communication between the two devices. From what I understand, one Android device will act as the USB Host (Nexus 7 running 4.4) and the other Android device will act as a USB Accessory (Galaxy Nexus running 4.2.2). I've tried googling around for an answer, but I can only seem to find articles explaining how to connect an Android device to a USB accessory (like a USB mouse or keyboard), not how to treat an Android device as the USB accessory itself.

因此,在这个页面之后,我配置了一个Nexus 7 上的应用程序成为 USB 主机.我可以根据其产品 ID & 找到连接的 Galaxy Nexus供应商 ID,形成与 Android 开放附件协议的连接并通过 USB 成功连接.据我所知,Nexus 7 可以成功地向 Galaxy Nexus 发送字节.

So, following this page, I have configured an app on the Nexus 7 to be the USB Host. I can find the connected Galaxy Nexus based on its product id & vendor id, form a connection to the Android Open Accessory Protocol and successfully connect over USB. From what I can tell, the Nexus 7 can successfully send bytes to the Galaxy Nexus.

我的问题是如何在 Galaxy Nexus 端访问此连接.我已将权限和 USB 过滤器添加到清单中,因此一旦建立 USB 连接,所需的应用程序就会在 Galaxy Nexus 上打开,但我不知道如何接收来自 Nexus 7 的数据或如何发送将数据从 Galaxy Nexus 传回 Nexus 7.

My question is how to access this connection on the Galaxy Nexus side. I have added permissions and the USB filter into the manifest, so the desired app opens on the Galaxy Nexus once the USB connection is established, but I can't figure out how to receive the data coming in from the Nexus 7 or how to send data from the Galaxy Nexus back to the Nexus 7.

任何帮助将不胜感激!谢谢!

Any help would be greatly appreciated! Thanks!

推荐答案

此处查看我的 SO 答案.

See my SO answer here.

如果您希望 Galaxy Nexus 充当 USB 配件,则它必须实现 Android 开放配件协议.Android 配件是一个 USB 主机,因此从技术上讲,您将有两个主机(假设您设法在 Galaxy Nexus 上正确实施了 AOA 协议),这显然是 USB 规范的偏差.

If you want the Galaxy Nexus to act as the USB Accessory, then it must implement the Android Open Accessory protocol. An Android Accessory is a usb host, so technically you would have two hosts (assuming you managed to implement correctly the AOA protocol on the Galaxy Nexus), which is clearly a deviation of the USB spec.

这篇关于作为配件的 Android 设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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