public void Stop() { bleAdvertisementWatcher.Received -= OnBleAdvertisementUpdated; bleAdvertisementWatcher.DestoryBleWatcher(); bluetoothWatcher.Received -= OnBluetoothDeviceUpdated; bluetoothWatcher.Stop(); PairingManager.FeatureStateChanged -= PairingManagerFeagtureChanged; PairingManager.Start(); PairedDeviceList.Clear(); BleDeviceUpdated?.Invoke(this, DeviceWatchEvent.Stopped, null); PairedDeviceUpdated?.Invoke(this, DeviceWatchEvent.Stopped, null); }
private void OnBluetoothDeviceUpdated(BluetoothWatcher sender, DeviceWatchEvent eventCode, DeviceInformation deviceInformation) { string deviceId = deviceInformation == null ? string.Empty : deviceInformation.Id; Log.D(string.Format($"OnBluetoothDeviceUpdated: {eventCode} {deviceId}")); switch (eventCode) { case DeviceWatchEvent.Added: AddPairedBtDevice(deviceInformation); break; case DeviceWatchEvent.Updated: UpdatePairedBtDevice(deviceInformation); break; case DeviceWatchEvent.Removed: RemovePairedBtDevice(deviceInformation); break; } PairedDeviceUpdated?.Invoke(this, eventCode, deviceInformation); }