I am working Bluetooth gatt with
minSdk 21
targetSdk 33
I see the writeDescriptor
is deprecated in sdk 33. So I did this to wrap the code in SDK version check
gatt.setCharacteristicNotification(characteristic, true)
val descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"))
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.TIRAMISU) {
descriptor.value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
gatt.writeDescriptor(descriptor)
} else {
gatt.writeDescriptor(descriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)
}
After I am still getting warning in gatt.writeDescriptor(descriptor)
in here
Also Do I need to to use 2 different types of onCharacteristicChanged
i.e.
In sdk 33
override fun onCharacteristicChanged(
gatt: BluetoothGatt,
characteristic: BluetoothGattCharacteristic,
value: ByteArray
) {
and below sdk 33
override fun onCharacteristicChanged(
gatt: BluetoothGatt?,
characteristic: BluetoothGattCharacteristic
) {
So what is the best way to solve this problem?