Skip to content

Commit ab6fb9d

Browse files
committed
automatically detect subscription type
automatically detect subscription type on Android so that isNotification param doesn’t need to be specified
1 parent 5fe7af5 commit ab6fb9d

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
@@ -957,7 +957,7 @@ bluetoothle.read(readSuccess, readError, params);
957957

958958

959959
### subscribe ###
960-
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.
960+
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.
961961

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

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

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";
@@ -1794,11 +1793,10 @@ private void subscribeAction(JSONArray args, CallbackContext callbackContext) {
17941793

17951794
boolean result = false;
17961795

1797-
//Set the descriptor for notification
1798-
if (obj.optBoolean(keyIsNotification, true)) {
1796+
//Use properties to determine whether notification or indication should be used
1797+
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
17991798
result = descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
18001799
} else {
1801-
//Or for indication
18021800
result = descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
18031801
}
18041802

0 commit comments

Comments
 (0)