I connect to a BLE device's GATT server in one area of my app and I'd like to disconnect from the device in another area of my app. The problem is that when I want to disconnect, I no longer have access to the BluetoothGatt
client object (which has the disconnect()
method). Is there any way to disconnect from a BLE device without a reference to a BluetoothGatt
?
Disconnect from connected BLE device's GATT server
2.8k views Asked by SuperDeclarative At
1
I would write your own basic abstraction layer. At its simplest it can be one class with one instance that you have some global reference to. Really basic stub example:
You would then add various methods like
connect()
anddisconnect()
that would operate on them_gatt
member. It's a good idea to write your own abstraction layer anyway because of all the quirks and bugs that you will start to discover with Android BLE. It's best to tuck those away behind a clean interface.