So I have a device where I need to put in a pin code, this all works however I can't detect when the bond has completed, only when bonding has started.
Android 10
if (action == BluetoothDevice.ACTION_BOND_STATE_CHANGED) {
val state = intent.extras?.get(BluetoothDevice.EXTRA_BOND_STATE) as Int
val device = getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
val previousBondState = getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1)
val bondState = getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1)
val bondTransition = "${previousBondState.toBondStateDescription()} to " +
bondState.toBondStateDescription()
Timber.w("${device?.address} bond state changed | $bondTransition ${state.toBondStateDescription()}")
}
fun listenToBondStateChanges(context: Context) {
context.applicationContext.registerReceiver(
viewModel.btConnectionManager.broadcastReceiver,
IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED)
)
}