コード例 #1
0
            public DiscoveryContext(Context applicationContext, BluetoothAdapter adapter)
            {
                this.applicationContext = applicationContext;
                this.adapter            = adapter;

                Receiver = new LambdaBroadcastReceiver(OnReceive);
            }
コード例 #2
0
        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);
        }