Android的USB主机模式和附件模式 [英] Android USB Host Mode and Accessory Mode

查看:1961
本文介绍了Android的USB主机模式和附件模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习Android的USB主机/附件连接。我读的Andr​​oid设备可以充当USB主机或USB附件。因此,我创建它们两个项目一个USB主机项目,其他的USB附件项目。我安装了这些项目,两个不同的Andr​​oid设备。他们中的一个具有USB主机(设备A)的项目,其他具有USB附件(设备B)项目。

我的问题是,我可以用USB主机连接的项目到设备B.我可以看到有关设备的所有信息。但在附件项目(设备B)我不能看到有关设备A.任何事情

manager.getAccessoryList()总是返回null。我的USB配件项目code是在这里。

  UsbManager经理=(UsbManager)getSystemService(Context.USB_SERVICE);对于(UsbAccessory附件:manager.getAccessoryList()){
    字符串列表=描述:+ accessory.getDescription()+模式:+ accessory.getModel()+制造商:+ accessory.getManufacturer()+SERIAL:+ accessory.getSerial();
    Toast.makeText(这一点,列表,Toast.LENGTH_LONG).show();
}


解决方案

这是因为当你的配件连接到设备B,你的配件这是作为美国B主机必须实现Android开放配件协议(AOAP)。请参见 连接通过USB 。由于设备A(主机),没有实现AOAP,设备B将拒绝超出握手学尝试与设备A进行通信。

I am trying to learn Android USB Host/Accessory connection. I read android devices can act usb host or usb accessory. Therefore I create two project one of them usb host project, other usb accessory project. I installed these projects to two different android devices. One of them has usb host(Device A) project, other has usb accessory(Device B) project.

My question is, I can connect with usb host project to Device B. I can see all information about device. But In accessory project( Device B) i can not see any thing about device A.

manager.getAccessoryList() always return null. My usb accessory project code is here.

UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

for (UsbAccessory accessory : manager.getAccessoryList()) {
    String list = " DESCRIPTION : " + accessory.getDescription() + " MODEL : " + accessory.getModel() + " MANUFACTURER : " + accessory.getManufacturer() + " SERIAL : " + accessory.getSerial();
    Toast.makeText(this, list, Toast.LENGTH_LONG).show();
}

解决方案

That's because when you connect an accessory to Device B, your accessory which is acting as US B host must implement the Android Open Accessory Protocol (AOAP). See Connecting over USB. Since Device A (host), does not implement the AOAP, Device B will refuse to communicate with Device A beyond a handshake attemp.

这篇关于Android的USB主机模式和附件模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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