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
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