diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-02 15:33:10 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2014-12-03 11:41:58 +0100 |
commit | 43536fcb2970bcf3fa67b36777a9cf16ff46363d (patch) | |
tree | 15d4a2a229e27d73652d030f7605c49da634e63c /src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java | |
parent | 243d396e554b7bd880d63636f315e2cfc7d08099 (diff) |
Android: Fix automatic notification sending when device demands it
Some BTLE devices enable notifications be default. However since
Android's BTLE API requires a call to
BluetoothGatt.setCharacteristicNotification(..) to forward them,
we have to peek at the ClientCharacteristicConfigurations during the
service detail discovery and tell Android to forward the notification
when required.
Change-Id: Ief419404694d70a1373218c1b8275ef868a49ddb
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java')
-rw-r--r-- | src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java index ea5d6ce6..edeacb82 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java @@ -347,6 +347,24 @@ public class QtBluetoothLE { leDescriptorRead(qtObject, descriptor.getCharacteristic().getService().getUuid().toString(), descriptor.getCharacteristic().getUuid().toString(), runningHandle+1, descriptor.getUuid().toString(), descriptor.getValue()); + + /* Some devices preset ClientCharacteristicConfiguration descriptors + * to enable notifications out of the box. However the additional + * BluetoothGatt.setCharacteristicNotification call prevents + * automatic notifications from coming through. Hence we manually set them + * up here. + */ + + if (descriptor.getUuid().compareTo(clientCharacteristicUuid) == 0) { + final int value = descriptor.getValue()[0]; + // notification or indication bit set? + if ((value & 0x03) > 0) { + Log.d(TAG, "Found descriptor with automatic notifications."); + mBluetoothGatt.setCharacteristicNotification( + descriptor.getCharacteristic(), true); + } + } + performServiceDetailDiscoveryForHandle(runningHandle + 1, false); } |