permanent bluetooth connection

China☆狼群 提交于 2019-12-10 12:16:46

问题


I have a task to write application, that will connect to not-mobile-phone device by blue tooth and this device will send some data every second(some statistics) and device shouldn't disconnect after sanding one batch of data. How can I do this?


回答1:


If you open up a bluetooth socket connection, it will stay open as long as you hold the reference to it and neither end closes.

A simple example is the Bluetooth Chat example. It shows how to connect two phones, but it also shows how to maintain the connection and check if it's still alive.

Also, in Android, it can be sometimes tricky to maintain the reference because Activities restart on orientation changes. Generally people put it in a Service and send data that way. It's a quick and easy way of maintaining the connection.



来源:https://stackoverflow.com/questions/7661195/permanent-bluetooth-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!