Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid or dismiss Android's Bluetooth pairing notification when I am doing programmatic pairing?

I have an app where I am programmatically controlling Bluetooth pairing and unpairing. I can pair before connection and unpair afterwards. The reason I need to do this is specific to my application and not in the scope of my question.

Basically what I am doing is:

  1. Get a reference ib to IBluetooth object as described in this answer
  2. Register a BroadcastReceiver for android.bluetooth.device.action.PAIRING_REQUEST
  3. Call ib.createBond(address)
  4. Wait for BroadcastReceiver to trigger
  5. Convert user pin into bytes with convertPinToBytes()
  6. Call ib.setPin(address, pinBytes) from within BroadcastReceiver

Anyways, this approach works great, except for the fact that when I do the pairing, I get a notification in the Status bar requesting that the user enter a PIN to complete the pairing. But this is in fact unnecessary, because by the time the user sees this, my app has already used setPin(). I'd really like for that notification to either a) not appear at all, or b) be dismissed automatically somehow.

I realize this may not even be possible, but I thought I would ask in case someone has a creative idea.

like image 870
Joel F Avatar asked Sep 07 '11 16:09

Joel F


People also ask

How do I stop Bluetooth pairing requests?

To do this, turn on Bluetooth, connect to the devices you are interested in, and then turn off Bluetooth discoverability. This way, the requesting device will not “see” your device and the requests will cease.

How do I manage Bluetooth devices on Android?

To connect to them, simply find out how to put the device in pairing mode until it shows up in your Bluetooth device list (this should be in the device's instructions or manual). Once it shows up, tap on it, confirm the pairing request, and you are all set to use it.


2 Answers

Try setting the confirmation first in the PAIRING_REQUEST

BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");  device.getClass().getMethod("setPairingConfirmation", boolean.class).invoke(device, true); device.getClass().getMethod("cancelPairingUserInput").invoke(device); 

This worked for me between two Android devices using RFCOMM but I'm not entering any PINs

like image 151
dimpey Avatar answered Sep 20 '22 17:09

dimpey


Since Android API 19 Google switched these Methods to public Methods, so there is no need for Reflection any more. :)

like image 32
Erik Mueller Avatar answered Sep 23 '22 17:09

Erik Mueller