Class DotNetCoreBluetoothScanner
- Namespace
- Bluetooth.Maui.Platforms.DotNetCore.Scanning
- Assembly
- Bluetooth.Maui.Platforms.DotNetCore.dll
Interface for managing and scanning Bluetooth devices.
public class DotNetCoreBluetoothScanner : BaseBluetoothScanner, INotifyPropertyChanged, IBluetoothScanner, IAsyncDisposable
- Inheritance
-
DotNetCoreBluetoothScanner
- Implements
- Inherited Members
Constructors
DotNetCoreBluetoothScanner(IBluetoothAdapter, IBluetoothRssiToSignalStrengthConverter, ITicker, IBluetoothNameProvider?, ILoggerFactory?)
Initializes a new instance of the BaseBluetoothScanner class.
public DotNetCoreBluetoothScanner(IBluetoothAdapter adapter, IBluetoothRssiToSignalStrengthConverter rssiToSignalStrengthConverter, ITicker ticker, IBluetoothNameProvider? nameProvider = null, ILoggerFactory? loggerFactory = null)
Parameters
adapterIBluetoothAdapterThe Bluetooth adapter associated with this scanner.
rssiToSignalStrengthConverterIBluetoothRssiToSignalStrengthConverterThe converter for RSSI to signal strength.
tickerITickerThe ticker for scheduling periodic refresh tasks.
nameProviderIBluetoothNameProviderOptional provider for Bluetooth device names.
loggerFactoryILoggerFactoryOptional logger factory for creating loggers.
Exceptions
Methods
NativeCreateDeviceFromAdvertisement(IBluetoothAdvertisement)
Creates a factory request for creating a Bluetooth device based on the received advertisement.
protected override IBluetoothRemoteDevice NativeCreateDeviceFromAdvertisement(IBluetoothAdvertisement advertisement)
Parameters
advertisementIBluetoothAdvertisementThe received Bluetooth advertisement.
Returns
- IBluetoothRemoteDevice
A factory request containing the necessary information to create a Bluetooth device.
Exceptions
NativeHasScannerPermissionsAsync()
Platform-specific implementation to check if scanner permissions are granted.
protected override ValueTask<bool> NativeHasScannerPermissionsAsync()
Returns
Remarks
Implement platform-specific permission checks. Should NOT throw exceptions. Return false if permissions cannot be determined.
Exceptions
NativeRefreshIsRunning()
Refreshes the native running state from the underlying platform.
protected override void NativeRefreshIsRunning()
Exceptions
NativeRequestScannerPermissionsAsync(bool, CancellationToken)
Platform-specific implementation to request scanner permissions.
protected override ValueTask NativeRequestScannerPermissionsAsync(bool requireBackgroundLocation, CancellationToken cancellationToken)
Parameters
requireBackgroundLocationboolAndroid-only: whether to request background location.
cancellationTokenCancellationTokenCancellation token to cancel the permission request operation.
Returns
Remarks
Implement platform-specific permission request dialogs. Throw native exceptions on failure - base class will wrap them in BluetoothPermissionException.
Exceptions
- Exception
Throw platform-specific exceptions (SecurityException, COMException, etc.) on failure.
- PlatformNotSupportedException
NativeStartAsync(ScanningOptions, TimeSpan?, CancellationToken)
Starts the native Bluetooth scanner with the specified options. This method is called by StartScanningAsync(ScanningOptions?, PermissionOptions?, TimeSpan?, CancellationToken) to perform platform-specific start operations.
protected override ValueTask NativeStartAsync(ScanningOptions scanningOptions, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
scanningOptionsScanningOptionsThe scanning options to use when starting the scanner.
timeoutTimeSpan?An optional timeout for the start operation.
cancellationTokenCancellationTokenAn optional cancellation token to cancel the start operation.
Returns
Exceptions
NativeStopAsync(TimeSpan?, CancellationToken)
Stops the native Bluetooth scanner. This method is called by StopScanningAsync(TimeSpan?, CancellationToken) to perform platform-specific stop operations.
protected override ValueTask NativeStopAsync(TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
timeoutTimeSpan?cancellationTokenCancellationToken