2

Quite a few posts (e.g. this, this or this) on this site have discussed how to detect a lost Bluetooth connection on Android. Essentially, one may register for broadcasts of the actions

  • BluetoothAdapter.ACTION_ACL_DISCONNECT_REQUESTED and
  • BluetoothAdapter.ACTION_ACL_DISCONNECTED.

However, when there are multiple slaves, how do I know which one of them is disconnected or about to disconnect?

Edit:

  1. My use case is a multiplayer game.
  2. The BluetoothSocket class has a method isConnected(), which seems useful, but it requires API level 14 (Android 4.0) or above.
Community
  • 1
  • 1
user740006
  • 1,759
  • 4
  • 20
  • 30

1 Answers1

1

In Android you can get to know about the states of devices. You can use android.bluetooth.BluetoothProfile interface. It provides an API called public abstract List<BluetoothDevice> getDevicesMatchingConnectionStates (int[] states) which return the list of all the bluetooth devices. You can specify states like STATE_CONNECTED, STATE_CONNECTING, STATE_DISCONNECTED, STATE_DISCONNECTING in the argument array. For more info please see this : http://developer.android.com/reference/android/bluetooth/BluetoothProfile.html#getDevicesMatchingConnectionStates(int[])

theJango
  • 1,100
  • 10
  • 22
  • Thanks for your answer. I'll try this method when I have time. – user740006 Jan 06 '15 at 03:28
  • The method is abstract. How can I make use of it? My use case is a multiplayer game in which multiple mobile phones are connected. Although the method you mentioned is implemented in BluetoothA2dp, BluetoothGatt, BluetoothGattServer, BluetoothHeadset, BluetoothHealth, these classes do not seem relevant. – user740006 Jan 07 '15 at 08:45