I am building an Android app targeting 5.0+ that uses BLE to connect to multiple peripherals. Each of these peripherals has many (~10) characteristics. Ideally, I would like to subscribe to notifications of changes for every single one of these characteristics.
However, my understanding from reading around is that Android's Bluetooth implementations enforce a hard limit on the number of simultaneous notifications that can be active. This question identifies where the limit is defined within the Android Bluetooth implementation, and also notes how the limit has changed over time:
Max concurrent active notifications (
BTA_GATTC_NOTIF_REG_MAX
):
- 4 on Android 4.3
- 7 on Android 4.4
- 15 on Android 5.0+
These numbers are confirmed by Dave Smith in this video where it is also suggested that:
In testing on 5.0+ devices, however, I have found that I am apparently able to successfully subscribe to more than 15 notifications. So far I have observed this on:
These notification subscriptions are successful by two measures:
GATT_SUCCESS
;This is mixed news. On the one hand, more "real" notifications ==> less manual polling ==> better user experience. On the other hand, being unable to create conditions that cause "real" notification setup to fail means I can't easily write or test the manual fallback code that will surely(?) be required once this app is released to real users.
The APIs are quite badly designed. Just the fact that this implementation uses a fixed size array rather than a dynamic array is probably a legacy from when the library was written in C.
The internal C++ library actually returns an error when it fails to allocate a notification entry. Unfortunately that error is only logged and is not propagated to the Java layer of the consuming application (source). This means that developers have no way to determine (in code) when they hit the limit.
Anyway, the BTA_GATTC_NOTIF_REG_MAX
limit is per BluetoothGatt
object, so if another app is connected it should not interfere with your notification registrations. You can even have two BluetoothGatt
objects in the same app connecting to the same device, and that way get double as many notification registration slots.
The max number of slots is defined here. It's incorrect that OS level is the only thing that defines this value, as manufacturers are free to change this value. For example I know that Samsung has in some of their devices increased the maximum number of connections (that is otherwise hardcoded to 7), so they might also have increased this value.
I can't explain how you succeeded in subscribing to more than 15 notifications on the Google phones. Did you configure more than 15 notifications on a single device or over many devices?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With