Table of Contents

Interface IBluetoothPairingManager

Namespace
Bluetooth.Abstractions.Scanning
Assembly
Bluetooth.Abstractions.Scanning.dll

Interface for managing Bluetooth pairing and bonding operations. Pairing establishes a secure connection between devices, while bonding stores the keys for future connections.

public interface IBluetoothPairingManager

Properties

Adapter

Gets the Bluetooth adapter associated with this pairing manager.

IBluetoothAdapter Adapter { get; }

Property Value

IBluetoothAdapter

Methods

GetClosestPairedDeviceOrDefault(Func<IBluetoothRemoteDevice, bool>?)

Returns the closest paired Bluetooth device currently available.

IBluetoothRemoteDevice? GetClosestPairedDeviceOrDefault(Func<IBluetoothRemoteDevice, bool>? filter = null)

Parameters

filter Func<IBluetoothRemoteDevice, bool>

An optional function to filter devices. Defaults to null for all devices.

Returns

IBluetoothRemoteDevice

The closest paired IBluetoothRemoteDevice, or null if none are found.

GetPairedDeviceOrDefault(Func<IBluetoothRemoteDevice, bool>)

Returns the first paired Bluetooth device that matches the specified filter.

IBluetoothRemoteDevice? GetPairedDeviceOrDefault(Func<IBluetoothRemoteDevice, bool> filter)

Parameters

filter Func<IBluetoothRemoteDevice, bool>

A function to filter devices. Should return true for matching devices.

Returns

IBluetoothRemoteDevice

The matching paired IBluetoothRemoteDevice, or null if none are found.

GetPairedDeviceOrDefault(string)

Returns a paired Bluetooth device with the specified ID.

IBluetoothRemoteDevice? GetPairedDeviceOrDefault(string id)

Parameters

id string

The ID of the device to retrieve.

Returns

IBluetoothRemoteDevice

The matching paired IBluetoothRemoteDevice, or null if none are found.

GetPairedDeviceOrWaitForDeviceToBePairedAsync(Func<IBluetoothRemoteDevice, bool>?, TimeSpan?, CancellationToken)

Returns a paired device immediately if it exists, otherwise waits for it to be paired.

ValueTask<IBluetoothRemoteDevice> GetPairedDeviceOrWaitForDeviceToBePairedAsync(Func<IBluetoothRemoteDevice, bool>? filter = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

filter Func<IBluetoothRemoteDevice, bool>

An optional function to filter devices. Defaults to null for all devices.

timeout TimeSpan?

The timeout for this operation.

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<IBluetoothRemoteDevice>

The matching paired IBluetoothRemoteDevice.

GetPairedDeviceOrWaitForDeviceToBePairedAsync(string, TimeSpan?, CancellationToken)

Returns a paired device by ID immediately if it exists, otherwise waits for it to be paired.

ValueTask<IBluetoothRemoteDevice> GetPairedDeviceOrWaitForDeviceToBePairedAsync(string id, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

id string

The ID of the device to retrieve.

timeout TimeSpan?

The timeout for this operation.

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<IBluetoothRemoteDevice>

The matching paired IBluetoothRemoteDevice.

GetPairedDevices(Func<IBluetoothRemoteDevice, bool>?)

Returns all paired Bluetooth devices that match the specified filter.

IEnumerable<IBluetoothRemoteDevice> GetPairedDevices(Func<IBluetoothRemoteDevice, bool>? filter = null)

Parameters

filter Func<IBluetoothRemoteDevice, bool>

An optional function to filter devices. Defaults to null for all devices.

Returns

IEnumerable<IBluetoothRemoteDevice>

A collection of paired IBluetoothRemoteDevice that match the filter.

IsPaired(IBluetoothRemoteDevice)

Checks if the specified device is currently paired (bonded).

bool IsPaired(IBluetoothRemoteDevice device)

Parameters

device IBluetoothRemoteDevice

The device to check.

Returns

bool

True if the device is paired, false otherwise.

IsPaired(string)

Checks if the specified device is currently paired (bonded) by its identifier.

bool IsPaired(string deviceId)

Parameters

deviceId string

The identifier of the device to check.

Returns

bool

True if the device is paired, false otherwise.

PairAsync(IBluetoothRemoteDevice, TimeSpan?, CancellationToken)

Pairs with the specified device asynchronously.

ValueTask<bool> PairAsync(IBluetoothRemoteDevice device, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

device IBluetoothRemoteDevice

The device to pair with.

timeout TimeSpan?

The timeout for this operation.

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<bool>

A task that represents the asynchronous pairing operation. The task result indicates whether pairing was successful.

Exceptions

ArgumentNullException

Thrown when device is null.

InvalidOperationException

Thrown when the device is already paired or pairing is not supported.

TimeoutException

Thrown when the operation times out.

OperationCanceledException

Thrown when the operation is cancelled.

UnpairAsync(IBluetoothRemoteDevice, TimeSpan?, CancellationToken)

Unpairs (removes bonding information) from the specified device asynchronously.

ValueTask UnpairAsync(IBluetoothRemoteDevice device, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

device IBluetoothRemoteDevice

The device to unpair.

timeout TimeSpan?

The timeout for this operation.

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask

A task that represents the asynchronous unpairing operation.

Exceptions

ArgumentNullException

Thrown when device is null.

InvalidOperationException

Thrown when the device is not paired or unpairing is not supported.

TimeoutException

Thrown when the operation times out.

OperationCanceledException

Thrown when the operation is cancelled.

WaitForDeviceToBePairedAsync(Func<IBluetoothRemoteDevice, bool>?, TimeSpan?, CancellationToken)

Waits for a device matching the filter to be paired.

ValueTask<IBluetoothRemoteDevice> WaitForDeviceToBePairedAsync(Func<IBluetoothRemoteDevice, bool>? filter = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

filter Func<IBluetoothRemoteDevice, bool>

An optional function to filter devices. Defaults to null for all devices.

timeout TimeSpan?

The timeout for this operation.

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<IBluetoothRemoteDevice>

The paired IBluetoothRemoteDevice.

WaitForDeviceToBePairedAsync(string, TimeSpan?, CancellationToken)

Waits for a device with the specified ID to be paired.

ValueTask<IBluetoothRemoteDevice> WaitForDeviceToBePairedAsync(string id, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

id string

The ID of the device to wait for.

timeout TimeSpan?

The timeout for this operation.

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<IBluetoothRemoteDevice>

The paired IBluetoothRemoteDevice.

Events

PairedDeviceListChanged

Event triggered when the list of paired devices changes.

event EventHandler<DeviceListChangedEventArgs>? PairedDeviceListChanged

Event Type

EventHandler<DeviceListChangedEventArgs>

PairedDevicesAdded

Event triggered when devices are added to the paired devices list.

event EventHandler<DevicesAddedEventArgs>? PairedDevicesAdded

Event Type

EventHandler<DevicesAddedEventArgs>

PairedDevicesRemoved

Event triggered when devices are removed from the paired devices list.

event EventHandler<DevicesRemovedEventArgs>? PairedDevicesRemoved

Event Type

EventHandler<DevicesRemovedEventArgs>

PairingStateChanged

Event raised when the pairing state changes for a device.

event EventHandler<PairingStateChangedEventArgs>? PairingStateChanged

Event Type

EventHandler<PairingStateChangedEventArgs>