To set the PIN, you can call by reflection the hidden method setPin(byte[])
from the BluetoothDevice
class.
Example:
try {
Log.d("setPin()", "Try to set the PIN");
Method m = device.getClass().getMethod("setPin", byte[].class);
m.invoke(device, pin);
Log.d("setPin()", "Success to add the PIN");
} catch (Exception e) {
Log.e("setPin()", e.getMessage());
}
Where device
is your BluetoothDevice
and pin
a byte[]
array which contains the bluetooth device pin.
But I think, you'll prefer to use the method setPasskey(int)
. It would be easier for you because you want to set a passkey like "0000" or "1234".
[UPDATE]
Previous source links are dead and the class has been updated. Apparently setPasskey
does not exist anymore. Follow the documentation link below to find the information you need.
Sources: BluetoothDevice Android documention