Example #1
0
        public Adapter()
        {
            ScanTimeout = 10000;

            DeviceOperationRegistry = new Dictionary <string, IDevice>();
            ConnectedDeviceRegistry = new Dictionary <string, IDevice>();

            var appContext = Android.App.Application.Context;

            // get a reference to the bluetooth system service
            this._manager = (BluetoothManager)appContext.GetSystemService(Context.BluetoothService);
            this._adapter = this._manager.Adapter;


            var bondStatusBroadcastReceiver = new BondStatusBroadcastReceiver();

            Application.Context.RegisterReceiver(bondStatusBroadcastReceiver,
                                                 new IntentFilter(BluetoothDevice.ActionBondStateChanged));

            //forward events from broadcast receiver
            bondStatusBroadcastReceiver.BondStateChanged += (s, args) =>
            {
                this.DeviceBondStateChanged(this, args);
            };

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                _api21ScanCallback = new Api21BleScanCallback(this);
            }
        }
Example #2
0
        public Adapter()
        {
            ScanTimeout = 10000;

            DeviceOperationRegistry = new Dictionary<string, IDevice>();
            ConnectedDeviceRegistry = new Dictionary<string, IDevice>();

            var appContext = Android.App.Application.Context;
            // get a reference to the bluetooth system service
            this._manager = (BluetoothManager)appContext.GetSystemService(Context.BluetoothService);
            this._adapter = this._manager.Adapter;


            var bondStatusBroadcastReceiver = new BondStatusBroadcastReceiver();
            Application.Context.RegisterReceiver(bondStatusBroadcastReceiver,
                new IntentFilter(BluetoothDevice.ActionBondStateChanged));

            //forward events from broadcast receiver
            bondStatusBroadcastReceiver.BondStateChanged += (s, args) =>
            {
                this.DeviceBondStateChanged(this, args);
            };

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                _api21ScanCallback = new Api21BleScanCallback(this);
            }
        }