public AndroidBluetooth(BTCallback btCallback) { this.callback = btCallback; btManager = (BluetoothManager)MainActivity.MainContext.GetSystemService(Context.BluetoothService); btAdapter = btManager.Adapter; scanCallback = new MyScanCallback(this); bluetoothGattCallback = new MyGattCallback(this); // Watch for Bluetooth Power Changes btCheckThread = new Thread(new ThreadStart(() => { bool lastState = false; while (true && btAdapter != null) { bool state = btAdapter.IsEnabled; if (state != lastState) { lastState = state; if (!state) { endEnumeration(); disconnect(); } callback.onBluetoothPowerChanged(state); } Thread.Sleep(100); } })); btCheckThread.Start(); }
public IOSBluetooth(BTCallback btCallback) { cmDelegate = new MyCentralmanagerDelegate(this); peripheralDelegate = new MyCBPeripheralDelegate(this); callback = btCallback; CBCentralInitOptions opts = new CBCentralInitOptions(); opts.ShowPowerAlert = false; centralManager = new CBCentralManager(cmDelegate, null, opts); }
#pragma warning disable 4014 public UWPBluetooth(BTCallback btCallback) { this.callback = btCallback; Task.Run(async() => { BtError error = await _checkBtSupport(); if (error != BtError.NoBluetooth && error != BtError.NoBLE) { var lastState = error == BtError.None; // Watch for bt power changes while (true) { BtError e = await _checkBtSupport(); var state = e == BtError.None; if (state != lastState) { lastState = state; // Should not wait for this. That would slow down checking for power changes callback.onBluetoothPowerChanged(state); } await Task.Delay(100); } } }); }