diff --git a/Source/Plugin.BLE/Windows/Adapter.cs b/Source/Plugin.BLE/Windows/Adapter.cs
index b14418ef..1c8d9257 100644
--- a/Source/Plugin.BLE/Windows/Adapter.cs
+++ b/Source/Plugin.BLE/Windows/Adapter.cs
@@ -16,6 +16,7 @@ namespace Plugin.BLE.Windows
{
public class Adapter : AdapterBase
{
+ private readonly BluetoothAdapter _bluetoothAdapter;
private BluetoothLEAdvertisementWatcher _bleWatcher;
///
@@ -24,8 +25,9 @@ public class Adapter : AdapterBase
///
private readonly IDictionary disconnectingRegistry = new ConcurrentDictionary();
- public Adapter()
+ public Adapter(BluetoothAdapter adapter)
{
+ _bluetoothAdapter = adapter;
}
public override async Task BondAsync(IDevice device)
@@ -264,13 +266,14 @@ private void AdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Blue
{
var deviceId = btAdv.BluetoothAddress.ParseDeviceId();
- if (DiscoveredDevicesRegistry.TryGetValue(deviceId, out var device) && device != null)
+ if (DiscoveredDevicesRegistry.TryGetValue(deviceId, out var device))
{
+ // This deviceId has been discovered
Trace.Message("AdvReceived - Old: {0}", btAdv.ToDetailedString(device.Name));
(device as Device)?.Update(btAdv.RawSignalStrengthInDBm, ParseAdvertisementData(btAdv.Advertisement));
- this.HandleDiscoveredDevice(device);
+ HandleDiscoveredDevice(device);
}
- if (device == null)
+ else
{
var bluetoothLeDevice = BluetoothLEDevice.FromBluetoothAddressAsync(btAdv.BluetoothAddress).AsTask().Result;
if (bluetoothLeDevice != null) //make sure advertisement bluetooth address actually returns a device
@@ -283,12 +286,7 @@ private void AdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, Blue
ParseAdvertisementData(btAdv.Advertisement),
btAdv.IsConnectable);
Trace.Message("AdvReceived - New: {0}", btAdv.ToDetailedString(device.Name));
- _ = DiscoveredDevicesRegistry.TryRemove(deviceId, out _);
- this.HandleDiscoveredDevice(device);
- }
- else
- {
- DiscoveredDevicesRegistry[deviceId] = null;
+ HandleDiscoveredDevice(device);
}
}
}
@@ -298,5 +296,10 @@ public override IReadOnlyList GetKnownDevicesByIds(Guid[] ids)
// TODO: implement this
return new List();
}
+
+ public override bool SupportsExtendedAdvertising()
+ {
+ return _bluetoothAdapter.IsExtendedAdvertisingSupported;
+ }
}
-}
\ No newline at end of file
+}
diff --git a/Source/Plugin.BLE/Windows/BleImplementation.cs b/Source/Plugin.BLE/Windows/BleImplementation.cs
index f5795ab0..9df8c411 100644
--- a/Source/Plugin.BLE/Windows/BleImplementation.cs
+++ b/Source/Plugin.BLE/Windows/BleImplementation.cs
@@ -22,7 +22,7 @@ public class BleImplementation : BleImplementationBase
protected override IAdapter CreateNativeAdapter()
{
- return new Adapter();
+ return new Adapter(btAdapter);
}
protected override BluetoothState GetInitialStateNative()