permanent bluetooth connection
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 开发者_StackOverflow社区do this?
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.
精彩评论