예제 #1
0
        internal void InitializeNative()
        {
            var ctx = Application.Context;

            if (!ctx.PackageManager.HasSystemFeature(PackageManager.FeatureBluetoothLe))
            {
                return;
            }

            var statusChangeReceiver = new BluetoothStatusBroadcastReceiver(state => State = state);

            ctx.RegisterReceiver(statusChangeReceiver, new IntentFilter(BluetoothAdapter.ActionStateChanged));

            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);

            if (ShouldQueueOnMainThread)
            {
                TaskBuilder.MainThreadInvoker = action =>
                {
                    if (IsMainThread)
                    {
                        action();
                    }
                    else
                    {
                        if (_handler == null)
                        {
                            _handler = new Handler(Looper.MainLooper);
                        }

                        _handler.Post(action);
                    }
                };
            }
        }
예제 #2
0
        protected override void InitializeNative()
        {
            var ctx = Application.Context;

            if (!ctx.PackageManager.HasSystemFeature(PackageManager.FeatureBluetoothLe))
            {
                return;
            }

            var statusChangeReceiver = new BluetoothStatusBroadcastReceiver(UpdateState);

            ctx.RegisterReceiver(statusChangeReceiver, new IntentFilter(BluetoothAdapter.ActionStateChanged));

            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
        }