public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
try {
BtConnectOperation.BtSetPairingConfirmation(device.getClass(), device);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mConnService.pairEnd();
}
}
}
其中这个BtSetPairingConfirmation函数如下,使用反射机制
//设置确定
static public boolean BtSetPairingConfirmation(Class btClass, BluetoothDevice device)
throws Exception {
Method SetPairingConfirmationMethod = btClass.getMethod("setPairingConfirmation",
boolean.class);
Boolean returnValue = false;
returnValue = (Boolean)SetPairingConfirmationMethod.invoke(device, true);
return returnValue;
}
为何还是不能直接自动配对呢,还是会弹出“蓝牙配对申请”框,请大神们给些意见,谢谢啊