通过反射调用隐藏的方法“setPin(byte [])”是解决方案.我共享代码.
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());
}
}
如果觉得《java连接设备连接给参数_如何通过蓝牙连接两个设备按参数发送配对代码? JAVA Android的...》对你有帮助,请点赞、收藏,并留下你的观点哦!