@@ -58,7 +58,7 @@ public class FlutterBluePlugin implements MethodCallHandler, RequestPermissionsR
58
58
private static final String TAG = "FlutterBluePlugin" ;
59
59
private static final String NAMESPACE = "plugins.pauldemarco.com/flutter_blue" ;
60
60
private static final int REQUEST_COARSE_LOCATION_PERMISSIONS = 1452 ;
61
- static final private UUID CCCD_ID = UUID .fromString ("000002902 -0000-1000-8000-00805f9b34fb" );
61
+ static final private UUID CCCD_ID = UUID .fromString ("00002902 -0000-1000-8000-00805f9b34fb" );
62
62
private final Registrar registrar ;
63
63
private final MethodChannel channel ;
64
64
private final EventChannel stateChannel ;
@@ -453,6 +453,10 @@ public void onMethodCall(MethodCall call, Result result) {
453
453
value = BluetoothGattDescriptor .DISABLE_NOTIFICATION_VALUE ;
454
454
}
455
455
456
+ if (!gattServer .setCharacteristicNotification (characteristic , request .getEnable ())){
457
+ result .error ("set_notification_error" , "could not set characteristic notifications to :" + request .getEnable (), null );
458
+ return ;
459
+ }
456
460
457
461
if (!cccDescriptor .setValue (value )) {
458
462
result .error ("set_notification_error" , "error when setting the descriptor value to: " + value , null );
@@ -464,18 +468,7 @@ public void onMethodCall(MethodCall call, Result result) {
464
468
return ;
465
469
}
466
470
467
- if (!gattServer .setCharacteristicNotification (characteristic , request .getEnable ())){
468
- result .error ("set_notification_error" , "could not set characteristic notifications to :" + request .getEnable (), null );
469
- return ;
470
- }
471
-
472
471
result .success (null );
473
-
474
- // SetNotificationResponse
475
- Protos .SetNotificationResponse .Builder q = Protos .SetNotificationResponse .newBuilder ();
476
- q .setRemoteId (gattServer .getDevice ().getAddress ());
477
- q .setCharacteristic (ProtoMaker .from (characteristic , gattServer ));
478
- channel .invokeMethod ("SetNotificationResponse" , q .build ().toByteArray ());
479
472
break ;
480
473
}
481
474
@@ -803,7 +796,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
803
796
804
797
@ Override
805
798
public void onDescriptorRead (BluetoothGatt gatt , BluetoothGattDescriptor descriptor , int status ) {
806
- Log .d (TAG , "onDescriptorRead: " );
799
+ Log .d (TAG , "onDescriptorRead: " + descriptor . getUuid (). toString () + " status: " + status );
807
800
if (descriptorReadSink != null ) {
808
801
// Rebuild the ReadAttributeRequest and send back along with response
809
802
Protos .ReadDescriptorRequest .Builder q = Protos .ReadDescriptorRequest .newBuilder ();
@@ -829,11 +822,12 @@ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descrip
829
822
p .setValue (ByteString .copyFrom (descriptor .getValue ()));
830
823
descriptorReadSink .success (p .build ().toByteArray ());
831
824
}
825
+
832
826
}
833
827
834
828
@ Override
835
829
public void onDescriptorWrite (BluetoothGatt gatt , BluetoothGattDescriptor descriptor , int status ) {
836
- Log .d (TAG , "onDescriptorWrite: " );
830
+ Log .d (TAG , "onDescriptorWrite: " + descriptor . getUuid (). toString () + " status: " + status );
837
831
Protos .WriteDescriptorRequest .Builder request = Protos .WriteDescriptorRequest .newBuilder ();
838
832
request .setRemoteId (gatt .getDevice ().getAddress ());
839
833
request .setDescriptorUuid (descriptor .getUuid ().toString ());
@@ -843,6 +837,14 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
843
837
p .setRequest (request );
844
838
p .setSuccess (status == BluetoothGatt .GATT_SUCCESS );
845
839
channel .invokeMethod ("WriteDescriptorResponse" , p .build ().toByteArray ());
840
+
841
+ if (descriptor .getUuid ().compareTo (CCCD_ID ) == 0 ) {
842
+ // SetNotificationResponse
843
+ Protos .SetNotificationResponse .Builder q = Protos .SetNotificationResponse .newBuilder ();
844
+ q .setRemoteId (gatt .getDevice ().getAddress ());
845
+ q .setCharacteristic (ProtoMaker .from (descriptor .getCharacteristic (), gatt ));
846
+ channel .invokeMethod ("SetNotificationResponse" , q .build ().toByteArray ());
847
+ }
846
848
}
847
849
848
850
@ Override
0 commit comments