With Android < 13, my app was able to connect to my Bluetooth device an everything worked. Now I had to upgrade to 13, an see following behaviour: the device connects but shortly after is gets into a loop of disconnects and connects.
I found that the problem starts with a call to writeDescriptor directly after the service discovery, where I want to enable notifications.
byte[] newDescriptorValue = enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
int r = bluetoothGatt.writeDescriptor(descriptor1, newDescriptorValue);
result = r == BluetoothGatt.GATT_SUCCESS;
The GATTCallback never gets called. Neither the onDescriptorWrite nor the onCharacteristicChanged. A timeout then triggers the disconnect.
I updated the GATTCallback to use the new callback functions for Android 13 instead of the old ones.
What am I missing?