I\'m trying to connect via bluetooth two devices. I\'ve been able to do it, but when the connections starts the OS ask me to provide the pairing code.
What I want to
I think this link will help you find what you need.
I was thinking more of the "Pairing is automatically performed when you initiate an encrypted connection with the Bluetooth APIs." part of the link. I haven't tried it but was thinking that pairing automatically means no user input.
Calling by reflection the hidden method "setPin(byte[])" was the solution.I share the code.
private void PairDevice(BluetoothDevice pDevice, String pin)
{
try
{
Log.d("pairDevice()", "Start Pairing...");
Method pairMethod = pDevice.getClass().getMethod("setPin", byte[].class);
Boolean lReturn = (Boolean) pairMethod.invoke(pDevice, pin.getBytes("UTF8"));
if(lReturn.booleanValue())
{
Log.d("pairDevice()", "Pairing Finished...");
Method bondMethod = pDevice.getClass().getMethod("createBond");
bondMethod.invoke(pDevice);
}
}
catch(Exception ex)
{
Log.e("pairDevice()", ex.getMessage());
}
}
Also, this answer with more details. Android bluetooth setpin function