0

In Bluetooth Low Energy (BLE), the connection status: connect and disconnect is performed in the function

 @Override
 public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {}

For example, when I connect the BLE with the phone, the above function is called and return the connection state. But I found one issue that is disconnection state. When the phone and BLE are connected, I will turn off the BLE, the above function is not called at that time. I must wait about 5-6 seconds to known the disconnection state. I think it is from scanning time. Is it possible to reduce the delay time. It means I want to know the disconnection state as soon as the BLE and phone are disconnected. Thank all

Jame
  • 3,746
  • 6
  • 52
  • 101

1 Answers1

0

Do you mean turn off Bluetooth on the android device? If so you could listen to Bluetooth state change (https://stackoverflow.com/a/9694138/556495). Or do you mean that you disconnect from the remote side? If so you should get the disconnect state change pretty quick. If you just shut down the remote end's radio you will get the disconnect state change after the specified supervision timeout.

Community
  • 1
  • 1
Emil
  • 16,784
  • 2
  • 41
  • 52
  • Thanks. I means turn off the BLE device, not the phone. In my BLE devices has a button to turn off the power. When I turn off it, the connected state still shows in my phone, until 5-10 seconds it will changes to disconnected state. I want to reduce the time – Jame Oct 21 '16 at 23:35
  • You should try to do a graceful disconnect rather than just turning off the power in order to decrease the disconnect time. Otherwise the phone will keep trying to get an answer from your BLE peripheral until it times out. You can control the supervision timeout by sending a Connection Parameter Update Request from your BLE peripheral. – Emil Oct 22 '16 at 00:00
  • Do you tried to run the sample BLE app. Then connect the BLE with the phone. After connected, you turned off the BLE device and see the connection state. it takes about 5 seconds to update. I want to reduce that time. I did not understand your solution – Jame Oct 22 '16 at 04:22