This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

[android]how to disconnect connection gracefully

hi, Nordic I'm using your nRF51-DK(PCA10028) board, on android, i disconnect connection by call BluetoothGatt.disconnect (developer.android.com/.../BluetoothGatt.html, it's work fine on almost android phones, but on some ones (such as xiaomi4LTE ) we can not disconnect connection successfully. so i try again with nRF-Connect (github.com/.../releases), nRF-Connect can disconnect it successfully. so my question is :

  1. how can i disconnect connection gracefully on android phone?
  2. what trick things nRF-Connect do in disconnecting working?

Thanks !!!

Parents
  • Hi, we don't do any magic in nRF Connect. The same method is used. Make sure you don't have nRF Connect (or any other app) with GATT server configured and not disabled running in background when you connect/disconnect from your app. Then the nRF Connect could just connect to it as well and your disconnect won't actually disconnect the physical connection as it is still being used by the nRF app. Just close the nRF Connect with the Back button instead of Home to make sure it's properly closed.

    When you disconnect, remember to call gatt.close() when you get the onConnectionStateChanged(state: disconnected).

    Also, I highly recommend using the BleManager class from nRF Toolbox. Or at least checking it. github.com/.../BleManager.java

    BR, Aleksander

Reply
  • Hi, we don't do any magic in nRF Connect. The same method is used. Make sure you don't have nRF Connect (or any other app) with GATT server configured and not disabled running in background when you connect/disconnect from your app. Then the nRF Connect could just connect to it as well and your disconnect won't actually disconnect the physical connection as it is still being used by the nRF app. Just close the nRF Connect with the Back button instead of Home to make sure it's properly closed.

    When you disconnect, remember to call gatt.close() when you get the onConnectionStateChanged(state: disconnected).

    Also, I highly recommend using the BleManager class from nRF Toolbox. Or at least checking it. github.com/.../BleManager.java

    BR, Aleksander

Children
Related