0

I'm developing an Android app that utilizes Bluetooth Low Energy (BLE) functionality. In my app, my device acts as a periphera. However, I've noticed that the pairing prompt dialog, which the Android system normally displays, is being skipped during the bonding process.

I understand that starting from Android 12, the system behavior for Bluetooth pairing has changed, and the pairing prompt may not always appear. However, I would like to ensure that the pairing prompt dialog always shows up on Android 13 to provide a consistent user experience.

Is there a way to solve this issue and ensure that the pairing prompt dialog is consistently displayed when bonding as a peripheral device on Android 13? I would greatly appreciate any insights, workarounds, or best practices that can help me achieve this goal.

Thank you in advance for your assistance!

Code:

private val broadCastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            val action = intent.action
            if (BluetoothDevice.ACTION_PAIRING_REQUEST == action) {
                val bluetoothDevice = intent.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
                if (ContextCompat.checkSelfPermission(context, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
                 
                    ActivityCompat.requestPermissions(
                        context as Activity,
                        arrayOf(Manifest.permission.BLUETOOTH_CONNECT),
                        BLUETOOTH_CONNECT_REQUEST_CODE
                    )
                    return
                }
                bluetoothDevice?.setPin(BLE_PIN.encodeToByteArray())
                bluetoothDevice?.createBond()
                
                if (bluetoothDevice != null) {
                    ConnectionManager.connect(bluetoothDevice, context.applicationContext)
                }
            }
        }
    }

I've attempted to use the setPairingConfirmation() method, which has been a valid approach in previous Android versions. However, since I'm targeting Android 13, this method is no longer suitable.

  • Is your android device the peripheral or the central? You say it's the peripheral but you also say it searches for a device to connect to – Michael Kotzjan Jun 28 '23 at 11:07
  • Sorry for my missinformation., its a peripheral app. – WhackedWhale Jun 30 '23 at 08:30
  • Do you receive a pairing request? Maybe writing something to your log could help figuring that out. Pairing BLE is only needed if at least one characteristic of the peripheral requires encryption. Is that the case? – Michael Kotzjan Jul 03 '23 at 06:44
  • Im getting a pairing request on the phone a Samsung s20. But when the phone vibrates and shows it wants to pair to a device this dialog skips. – WhackedWhale Jul 06 '23 at 14:32

0 Answers0