Skip to content

Commit b8c7a7b

Browse files
committed
Fixed losing a notification that occurs before calling setCharacteristicNotification
1 parent 2a899e6 commit b8c7a7b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/android/BluetoothLePlugin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,17 @@ private boolean subscribeAction(Operation operation) {
18311831
return false;
18321832
}
18331833

1834-
boolean result = false;
1834+
//Subscribe to the characteristic
1835+
boolean result = bluetoothGatt.setCharacteristicNotification(characteristic, true);
1836+
1837+
if (!result) {
1838+
addProperty(returnObj, keyError, errorWriteDescriptor);
1839+
addProperty(returnObj, keyMessage, logWriteDescriptorValueNotSet);
1840+
callbackContext.error(returnObj);
1841+
return false;
1842+
}
1843+
1844+
result = false;
18351845

18361846
//Use properties to determine whether notification or indication should be used
18371847
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
@@ -4239,23 +4249,13 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
42394249

42404250
callbackContext.success(returnObj);
42414251
} else {
4242-
//Subscribe to the characteristic
4243-
boolean result = gatt.setCharacteristicNotification(characteristic, true);
4244-
42454252
CallbackContext callbackContext = GetCallback(characteristicUuid, connection, operationSubscribe);
42464253

42474254
//If no callback, just return
42484255
if (callbackContext == null) {
42494256
return;
42504257
}
42514258

4252-
if (!result) {
4253-
addProperty(returnObj, keyError, errorSubscription);
4254-
addProperty(returnObj, keyMessage, logSubscribeFail);
4255-
callbackContext.error(returnObj);
4256-
return;
4257-
}
4258-
42594259
addProperty(returnObj, keyStatus, statusSubscribed);
42604260

42614261
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, returnObj);

0 commit comments

Comments
 (0)