Is there any way to forcefully click on "pair button" whenever the Bluetooth pairing dialog appears?
Asked
Active
Viewed 2,952 times
1
-
http://stackoverflow.com/questions/17168263/how-to-pair-bluetooth-device-programmatically-android – Tom Oct 22 '13 at 21:07
1 Answers
3
I don't know how to get access to the pairing dialog, but I was able to "force" pairing in the following way:
1) register a BroadcastReceiver for the action:
android.bluetooth.device.action.PAIRING_REQUEST
2) once the action is received, "force" the PIN using reflection:
String DEVICE_PIN = "12345";
final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (intent.getAction().equals("android.bluetooth.device.action.PAIRING_REQUEST")) {
byte[] pin = (byte[]) BluetoothDevice.class.getMethod("convertPinToBytes", String.class).invoke(BluetoothDevice.class, ARDUINO_PIN);
BluetoothDevice.class.getMethod("setPin", byte[].class).invoke(device, pin);
}
It worked for me on GB and ICS (don't know if it works on newer releases).

Stefano S.
- 242
- 2
- 3
-
I know this method but i want to know how to get access to the pairing dialog anyways thanks for the reply. – Muhammad Zeeshan Oct 30 '13 at 09:02