4

I have a list of BluetoothDevice and I want to pair programmatically with one of them that has a PIN.
I have read several posts here in which the subject is discussed, but I've found two very different approachs.

FIRST OPTION: You call the device.createBond() method. Then, on a BroadcastReceiver, you listen the BluetoothDevice.ACTION_PAIRING_REQUEST action and there you call device.setPin(PIN_BYTES); device.setPinConfirmation(true);

You can see the complete example & post here: How to pair Bluetooth device programmatically Android

SECOND OPTION: What if you call device.setPin(PIN_BYTES) and device.setPinConfirmation(true) first, and then device.createBond()? Eg:

if(connConfig!=null && connConfig.bluetooth!=null){
    device.setPin(connConfig.bluetooth.pass);
    device.setPairingConfirmation(true);
    device.createBond();
}

And then you forget about listening the BluetoothDevice.ACTION_PAIRING_REQUEST action on your BroadcastReceiver and only pay attention to BluetoothDevice.ACTION_BOND_STATE_CHANGED events? Android + Pair devices via bluetooth programmatically
See in the first answer the code. As far as I get it, that dude isn't using any PIN for pairing, so I also need to use the setPin method.

Which of both you find better?
Am I missing something? BTW: I'm not using reflection because Im not targeting older platforms.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gabo Alvarez
  • 139
  • 8
  • Your question is not clear. The only real questions I can see are *"Which of both you find better?"* and *"Am I missing something?"* which are asking for opinions and that is off-topic. Please [edit] your question to make it clearer. Please also read the [help] pages about how to write a good question and about what sort of questions are allowed. – AdrianHHH Jan 17 '17 at 09:15
  • @gabdev Did you find a sensible solution to your question? I am wondering the same right now. – IgorGanapolsky Apr 04 '17 at 15:53

0 Answers0