-
Notifications
You must be signed in to change notification settings - Fork 583
FAQ: Bonding
TL;DR — Yes
Bonding is performed and managed by the Android Operating System. The OS presents the UI to the user if/when needed.
There are three typical scenarios.
- Connect to peripheral
- Perform service discovery
- Perform action on a characteristic that requires authorization
At this point peripheral returns Gatt status == 5
which means GATT_INSUF_AUTHENTICATION
. This response triggers bonding process on the client see below OS Bonding UI
. The response may or may not be returned by the OS to the library depending on system version / vendor. Successful bonding may or may not trigger automatic action retry — again depending on system version / vendor.
- Connect to peripheral
- Peripheral requests bonding
Simple as that. User is presented with OS Bonding UI
(see below). To get info about bond state changes one needs to implement a BroadcastReceiver
with BluetoothDevice.ACTION_BOND_STATE_CHANGED
. As of library version 1.11.0
there is no convenience Observable
for such occasion.
- Central requests bonding
Since API 19 is possible to call BluetoothDevice.createBond()
. It is discouraged though as bonding parameters like transport layer (BLE/Classic) will be decided by the OS which may pick a wrong one.
Depending on OS version / vendor and supported bonding procedure user will be presented with native UI that is generally not controllable* by the application. Usually this UI involves a notification which user needs to click in order to bond.
Under some circumstances it was possible that Bonding UI will include a foreground popup. As of Android 10 this function cannot be found and BluetoothPairingService seems to only work with notifications.
* It is possible to hijack bonding in a way and alter default OS behaviour (version dependent) but these are out of scope of this library and can be implemented by you. YMMV.