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.