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;
}
爲何還是不能直接自動配對呢,還是會彈出“藍牙配對申請”框,請大神們給些意見,謝謝啊