0

Ive gotten an app based on the Bluetooth Chat sample for android that im trying to modify the service to run constantly in the background. I want to do this so that it can search and connect to a device as I approach it and not have to open the app and manually connect. Ive come across two problems:

Edit with change

  1. How can I figure out if there is already a connection on startup

  2. How can I reconnect to service on app startup if the service is running

DRing
  • 6,825
  • 6
  • 29
  • 45

2 Answers2

0

well if i am getting your problem. You should use TimerTask method in background service,and your TimerTask method will contineously execute in some interval and put your method inside it for checking bluetooth range ,if found range then call method for connecting blutooth.

MR. Kumar
  • 661
  • 8
  • 25
0
  1. You can use SharedPreference to keep track a "isConnected" variable. You set the variable to true here: case BluetoothChatService.STATE_CONNECTED:

and false here: case BluetoothChatService.STATE_NONE:

2: Keep a copy of the MAC address and connect it directly.

ksu
  • 882
  • 1
  • 11
  • 17