正确的方法来关闭USB配件连接 [英] Proper way to close a USB accessory connection

查看:833
本文介绍了正确的方法来关闭USB配件连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是正确的方法来关闭机器人到 UsbAccessory 的连接? 看来,即使在股票谷歌的例子,如果我连和附件,退出程序,然后回去吧,是不是重新建立连接。

What is the proper way to close a connection to a UsbAccessory in Android? It seems the even in the stock Google example, if I connect and accessory, exit the app and then go back to it, the connection is not re-established.

仔细观察,它似乎在调用后关闭()的FileDescriptor ,也不会再开和无法打开/ dev / usb_accessory日志发出。 不叫关闭()是个不错的选择,作为一个线程阻塞在阅读()将不会被释放。当物理断开/设备的一切重新连接正常。

Looking closely, it seems that after calling close() on the FileDescriptor, it won't open again, and a "could not open /dev/usb_accessory" log is emitted. NOT calling close() is a bad option, as a thread blocking on read() will not be released. Upon physical disconnection / reconnection of the device everything is OK.

这似乎真的令人惊讶的是简单的用例退出应用程序,然后打开它再次不中参考应用工作,更令人惊讶的,如果它是不可行的。

It seems really surprising that the simple use-case of exiting the app and then opening it again does not work in the reference application and even more surprising if it is not feasible.

我使用的是Nexus S的运行普通的Andr​​oid 2.3.6。

I'm using a Nexus S running stock Android 2.3.6.

推荐答案

问题是,读线程永远不会退出,从而文件描述符保持打开,不能再次打开该应用程序恢复时。

The problem is that the reading thread never exits, thus the file descriptor stays open, and cannot be opened again when the app is resumed.

这已被证实是一个错误: <一href="http://$c$c.google.com/p/android/issues/detail?id=20545">http://$c$c.google.com/p/android/issues/detail?id=20545

This has been confirmed to be a bug: http://code.google.com/p/android/issues/detail?id=20545

投票的错误,如果你关心它。

Vote on this bug if you care about it.

这篇关于正确的方法来关闭USB配件连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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