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:
ib
to IBluetooth
object as described in this answer
android.bluetooth.device.action.PAIRING_REQUEST
ib.createBond(address)
ib.setPin(address, pinBytes)
from within BroadcastReceiverAnyways, 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.
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.
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.
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
Since Android API 19 Google switched these Methods to public Methods, so there is no need for Reflection any more. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With