Skip to content

Commit 93ecedb

Browse files
authored
Merge pull request #625 from dki1110/master
Fixed losing a notification on Android
2 parents fb8398e + b8c7a7b commit 93ecedb

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
@@ -1833,7 +1833,17 @@ private boolean subscribeAction(Operation operation) {
18331833
return false;
18341834
}
18351835

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

18381848
//Use properties to determine whether notification or indication should be used
18391849
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
@@ -4248,23 +4258,13 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
42484258

42494259
callbackContext.success(returnObj);
42504260
} else {
4251-
//Subscribe to the characteristic
4252-
boolean result = gatt.setCharacteristicNotification(characteristic, true);
4253-
42544261
CallbackContext callbackContext = GetCallback(characteristicUuid, connection, operationSubscribe);
42554262

42564263
//If no callback, just return
42574264
if (callbackContext == null) {
42584265
return;
42594266
}
42604267

4261-
if (!result) {
4262-
addProperty(returnObj, keyError, errorSubscription);
4263-
addProperty(returnObj, keyMessage, logSubscribeFail);
4264-
callbackContext.error(returnObj);
4265-
return;
4266-
}
4267-
42684268
addProperty(returnObj, keyStatus, statusSubscribed);
42694269

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

0 commit comments

Comments
 (0)