(*** Edit #2: Trying to connect multiple devices ***)
I am using BluetoothDevice.connectGatt() with auto-connect set to true to connect to multiple devices:
bluetoothDevice1.connectGatt(context, true, BLGattCallback(context), BluetoothDevice.TRANSPORT_LE)
bluetoothDevice2.connectGatt(context, true, BLGattCallback(context), BluetoothDevice.TRANSPORT_LE)
(*** Edit # 1 ***) I use onConnectionStateChange() in BluetoothGattCallback():
internal class BLGattCallback(val context: BTLeashService) : BluetoothGattCallback() // Todo: Convert to LiveData
{
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int)
{
super.onConnectionStateChange(gatt, status, newState)
val connectionStateChange = BLBluetoothManager.ConnectionStateChange(gatt, status, newState)
BLBluetoothManager.connectionStateChange.postValue(connectionStateChange)
}
(End Edit #1)
With this method I have to use a delay before executing my next connectGat() or else the previous one gets aborted. Why is this? I thought that it was not supposed to wait and just give a call back whenever it connects...
Is there a callback to let you know when the first connectGatt is complete so that I don't need an ad hock delay?
*** Edit #3 ***
By "first connectGatt is complete" I don't mean that a connection was made, only that I can now execute my next command without aborting the previous.
(End Edit #3)