Skip to content

Commit 34b4cdb

Browse files
committed
Merge pull request #260 from randdusing/indication
automatically detect subscription type
2 parents 7cfc244 + ab6fb9d commit 34b4cdb

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ bluetoothle.read(readSuccess, readError, params);
958958

959959

960960
### subscribe ###
961-
Subscribe to a particular service's characteristic. Once a subscription is no longer needed, execute unsubscribe in a similar fashion. The Client Configuration descriptor will automatically be written to enable notification/indication.
961+
Subscribe to a particular service's characteristic. Once a subscription is no longer needed, execute unsubscribe in a similar fashion. The Client Configuration descriptor will automatically be written to enable notification/indication based on the characteristic's properties.
962962

963963
```javascript
964964
bluetoothle.subscribe(subscribeSuccess, subscribeError, params);
@@ -968,14 +968,12 @@ bluetoothle.subscribe(subscribeSuccess, subscribeError, params);
968968
* address = The address/identifier provided by the scan's return object
969969
* service = The service's UUID
970970
* characteristic = The characteristic's UUID
971-
* isNotification is only required on Android. True (or null) means notification will be enabled. False means indication will be enabled.
972971

973972
```javascript
974973
{
975974
"address": "ECC037FD-72AE-AFC5-9213-CA785B3B5C63",
976975
"service": "180d",
977976
"characteristic": "2a37",
978-
"isNotification" : true
979977
}
980978
```
981979

src/android/BluetoothLePlugin.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ public class BluetoothLePlugin extends CordovaPlugin {
148148
private final String keyIsScanning = "isScanning";
149149
private final String keyIsConnected = "isConnected";
150150
private final String keyIsDiscovered = "isDiscovered";
151-
private final String keyIsNotification = "isNotification";
152151
private final String keyPeripheral = "peripheral";
153152
private final String keyState = "state";
154153
private final String keyDiscoveredState = "discoveredState";
@@ -1801,11 +1800,10 @@ private void subscribeAction(JSONArray args, CallbackContext callbackContext) {
18011800

18021801
boolean result = false;
18031802

1804-
//Set the descriptor for notification
1805-
if (obj.optBoolean(keyIsNotification, true)) {
1803+
//Use properties to determine whether notification or indication should be used
1804+
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
18061805
result = descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
18071806
} else {
1808-
//Or for indication
18091807
result = descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
18101808
}
18111809

0 commit comments

Comments
 (0)