1515package com .megster .cordova .ble .central ;
1616
1717import android .annotation .SuppressLint ;
18+ import android .annotation .TargetApi ;
1819import android .app .Activity ;
1920
2021import android .bluetooth .*;
3334
3435import java .lang .reflect .Method ;
3536import java .util .concurrent .atomic .AtomicBoolean ;
37+
38+ import androidx .annotation .NonNull ;
39+ import androidx .annotation .RequiresApi ;
3640import androidx .annotation .RequiresPermission ;
3741
3842/**
@@ -432,9 +436,15 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
432436
433437 }
434438
439+ @ TargetApi (32 /*S_V2*/ )
435440 @ Override
436441 public void onCharacteristicChanged (BluetoothGatt gatt , BluetoothGattCharacteristic characteristic ) {
437442 super .onCharacteristicChanged (gatt , characteristic );
443+ if (Build .VERSION .SDK_INT >= 33 ) {
444+ // handled by new callback below
445+ return ;
446+ }
447+
438448 LOG .d (TAG , "onCharacteristicChanged %s" , characteristic );
439449
440450 SequentialCallbackContext callback = notificationCallbacks .get (generateHashKey (characteristic ));
@@ -444,9 +454,28 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
444454 }
445455 }
446456
457+ @ RequiresApi (api = 33 /*TIRAMISU*/ )
458+ @ Override
459+ public void onCharacteristicChanged (@ NonNull BluetoothGatt gatt , @ NonNull BluetoothGattCharacteristic characteristic , @ NonNull byte [] data ) {
460+ super .onCharacteristicChanged (gatt , characteristic , data );
461+ LOG .d (TAG , "onCharacteristicChanged (api:33) %s" , characteristic );
462+
463+ SequentialCallbackContext callback = notificationCallbacks .get (generateHashKey (characteristic ));
464+
465+ if (callback != null ) {
466+ callback .sendSequentialResult (data );
467+ }
468+ }
469+
470+ @ TargetApi (32 /*S_V2*/ )
447471 @ Override
448472 public void onCharacteristicRead (BluetoothGatt gatt , BluetoothGattCharacteristic characteristic , int status ) {
449473 super .onCharacteristicRead (gatt , characteristic , status );
474+ if (Build .VERSION .SDK_INT >= 33 ) {
475+ // handled by new callback below
476+ return ;
477+ }
478+
450479 LOG .d (TAG , "onCharacteristicRead %s" , characteristic );
451480
452481 synchronized (this ) {
@@ -464,6 +493,27 @@ public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic
464493 commandCompleted ();
465494 }
466495
496+ @ RequiresApi (api = 33 /*TIRAMISU*/ )
497+ @ Override
498+ public void onCharacteristicRead (@ NonNull BluetoothGatt gatt , @ NonNull BluetoothGattCharacteristic characteristic , @ NonNull byte [] value , int status ) {
499+ super .onCharacteristicRead (gatt , characteristic , value , status );
500+ LOG .d (TAG , "onCharacteristicRead (api:33) %s" , characteristic );
501+
502+ synchronized (this ) {
503+ if (readCallback != null ) {
504+ if (status == BluetoothGatt .GATT_SUCCESS ) {
505+ readCallback .success (value );
506+ } else {
507+ readCallback .error ("Error reading " + characteristic .getUuid () + " status=" + status );
508+ }
509+
510+ readCallback = null ;
511+ }
512+ }
513+
514+ commandCompleted ();
515+ }
516+
467517 @ Override
468518 public void onCharacteristicWrite (BluetoothGatt gatt , BluetoothGattCharacteristic characteristic , int status ) {
469519 super .onCharacteristicWrite (gatt , characteristic , status );
0 commit comments