Table of Contents

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

adapter IBluetoothAdapter

The Bluetooth adapter associated with this scanner.

rssiToSignalStrengthConverter IBluetoothRssiToSignalStrengthConverter

The converter for RSSI to signal strength.

ticker ITicker

The ticker for scheduling periodic refresh tasks.

nameProvider IBluetoothNameProvider

Optional provider for Bluetooth device names.

loggerFactory ILoggerFactory

Optional logger factory for creating loggers.

Exceptions

PlatformNotSupportedException

Methods

NativeCreateDeviceFromAdvertisement(IBluetoothAdvertisement)

Creates a factory request for creating a Bluetooth device based on the received advertisement.

protected override IBluetoothRemoteDevice NativeCreateDeviceFromAdvertisement(IBluetoothAdvertisement advertisement)

Parameters

advertisement IBluetoothAdvertisement

The received Bluetooth advertisement.

Returns

IBluetoothRemoteDevice

A factory request containing the necessary information to create a Bluetooth device.

Exceptions

PlatformNotSupportedException

NativeHasScannerPermissionsAsync()

Platform-specific implementation to check if scanner permissions are granted.

protected override ValueTask<bool> NativeHasScannerPermissionsAsync()

Returns

ValueTask<bool>

True if permissions are granted, otherwise false.

Remarks

Implement platform-specific permission checks. Should NOT throw exceptions. Return false if permissions cannot be determined.

Exceptions

PlatformNotSupportedException

NativeRefreshIsRunning()

Refreshes the native running state from the underlying platform.

protected override void NativeRefreshIsRunning()

Exceptions

PlatformNotSupportedException

NativeRequestScannerPermissionsAsync(bool, CancellationToken)

Platform-specific implementation to request scanner permissions.

protected override ValueTask NativeRequestScannerPermissionsAsync(bool requireBackgroundLocation, CancellationToken cancellationToken)

Parameters

requireBackgroundLocation bool

Android-only: whether to request background location.

cancellationToken CancellationToken

Cancellation token to cancel the permission request operation.

Returns

ValueTask

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

scanningOptions ScanningOptions

The scanning options to use when starting the scanner.

timeout TimeSpan?

An optional timeout for the start operation.

cancellationToken CancellationToken

An optional cancellation token to cancel the start operation.

Returns

ValueTask

Exceptions

PlatformNotSupportedException

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

timeout TimeSpan?
cancellationToken CancellationToken

Returns

ValueTask

Exceptions

PlatformNotSupportedException