I'm running Android Things on my Pi and I connected it with a Bluetooth Low-Energy device using the method 'connectGatt()'. But I just can't seem to disconnect it!
I'm finally forced to kill the application and when I reopen it to enable the broadcasting mode for visibility, it tells me that the app was not disconnected properly.
I'm sharing my code snippet for the disconnectivity of the device if anybody could tell me if I've missed out on something or done some mistakes in it:
private void disconnectDevice() {
gatt.disconnect();
}
//I've closed the connection here
private BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
switch (newState) {
case BluetoothProfile.STATE_CONNECTED:
Log.d("BLED-GATT", "STATE_CONNECTED");
setUIConnectionStatus("Discover services on device...", Color.YELLOW);
checkEnableAddButton(simpleTrackEditText.getText().toString());
gatt.discoverServices();
break;
case BluetoothProfile.STATE_DISCONNECTED:
Log.d("BLED-GATT", "STATE_DISCONNECTED");
setUIConnectionStatus("Not Connected!", Color.RED);
gatt.close();
break;
default:
Log.d("BLED-GATT", "STATE_OTHER");
}
}
}
The entire things executes but neither does my broadcasting mode change and nor does my device disconnect.
Please Help!
Thanks in Advance. :)