public DiscoveryContext(Context applicationContext, BluetoothAdapter adapter) { this.applicationContext = applicationContext; this.adapter = adapter; Receiver = new LambdaBroadcastReceiver(OnReceive); }
public AutomaticPairingService(Context applicationContext) { this.applicationContext = applicationContext; var filter = new IntentFilter(); filter.AddAction(BluetoothDevice.ActionPairingRequest); receiver = new LambdaBroadcastReceiver((context, intent) => { if (intent.Action != BluetoothDevice.ActionPairingRequest) { throw new InvalidStateException(); } int pin = intent.GetIntExtra(BluetoothDevice.ExtraPairingKey, 0); var pinBytes = Encoding.UTF8.GetBytes("" + pin); var device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); device.SetPin(pinBytes); device.SetPairingConfirmation(true); }); applicationContext.RegisterReceiver(receiver, filter); }