BluetoothGattServer cancelConnection does not cancel the connection

I have an Android app that provides a BLE server. I am connecting to BluetoothGattServer # connect . This works - my application receives a BluetoothGattServerCallback # onConnectionStateChange call with STATE_CONNECTED . When I am done with the client, I try to disconnect from my application using BluetoothGattServer # cancelConnection .

But I do not call BluetoothGattServerCallback # onConnectionStateChange , and it seems that the connection is still active, since my BLE Client does not start advertising (what it does when nothing is connected to it).

In logcat, I only see:

BluetoothGattServer: cancelConnection() - device: XX:XX:XX:XX:XX:XX 

The funny thing is, my application receives a call to BluetoothGattServerCallback # onConnectionStateChange with STATE_DISCONNECTED as soon as I completely turn off BT.

Similar issues in Google tracker: 63461 and 63464 .

+8
source share
3 answers

Detecting the same problem when calling the disconnect () method. On my BluetoothGattCallback connection, the connection in onConnectionStateChange does not disconnect.

Bluetooth cycling seems to be the only thing that works.

edit: also, after calling the disconnect () and close () methods, I am still connected according to this code:

 public int getConnectedBLEDevices() { int i = 0; List<BluetoothDevice> devices = mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT); for(BluetoothDevice device : devices) { if(device.getType() == BluetoothDevice.DEVICE_TYPE_LE) { Logs.writeEvent(TAG+".getConnectedBLEDevices()", device.getAddress() + "\n"+ getStateAsString(mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT))); i++; } } return i; } 
+2
source

When newState == BluetoothProfile.STATE_CONNECTED, you should call BluetoothGattServer.connect ();.

 @Override public void onConnectionStateChange(BluetoothDevice device, int status, int newState) { super.onConnectionStateChange(device, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED){ mDevice = device; mBluetoothGattServer.connect(device, false); }else { mDevice = null; } } private void cancelConnection(){ if (mDevice != null) { mBluetoothGattServer.cancelConnection(mDevice); } } 
0
source

Please see link description here

Status: will not be fixed (assumed behavior) You must call BluetoothGattServer.connect () to mark the connection as used, then BluetoothGattServer.disconnect () to mark it as unused. Then, after a timeout period, the stack may decide to disconnect from the console if no one else is using the connection. If BluetoothGattServer.connect () is not called after a connection is established, then the stack remains connected until a gatt client-server application begins to use this connection.

0
source

All Articles