Microsoft Docs

Bluetooth API Reference (Windows Runtime)

This section provides API documentation for Bluetooth functionality within the Windows Runtime (UWP) ecosystem. Learn how to discover, connect, and communicate with Bluetooth devices from your Windows applications.

Namespaces

Windows.Devices.Bluetooth.GenericAttributeProfile

Provides APIs for interacting with Bluetooth Low Energy (BLE) devices using the Generic Attribute Profile (GATT).

GattDeviceCharacteristic

Represents a characteristic within a GATT service.

Methods

  • Windows.Foundation.IAsyncOperation ReadValueAsync()
    Reads the value of the characteristic asynchronously.
    Returns
    • An asynchronous operation that returns a Windows.Storage.Streams.IBuffer representing the characteristic's value.
    // Example: Reading a characteristic value var result = await characteristic.ReadValueAsync(); if (result.Status == GattCommunicationStatus.Success) { var buffer = result.Value; // Process the buffer... }
  • Windows.Foundation.IAsyncOperation WriteValueAsync(Windows.Storage.Streams.IBuffer value)
    Writes a value to the characteristic asynchronously.
    Parameters
    • value: Windows.Storage.Streams.IBuffer - The data to write to the characteristic.
    Returns
    • An asynchronous operation that returns a Windows.Devices.Bluetooth.GenericAttributeProfile.GattWriteResult indicating the outcome of the write operation.
    // Example: Writing a characteristic value var writer = new DataWriter(); writer.WriteByte(0x01); // Example byte var buffer = writer.DetachBuffer(); var result = await characteristic.WriteValueAsync(buffer); if (result.Status == GattCommunicationStatus.Success) { // Write successful }
  • Windows.Foundation.IAsyncOperation WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue clientCharacteristicConfigurationDescriptor)
    Writes the client characteristic configuration descriptor for the characteristic asynchronously. This is used to enable or disable notifications/indications.
    Parameters
    • clientCharacteristicConfigurationDescriptor: Windows.Devices.Bluetooth.GenericAttributeProfile.GattClientCharacteristicConfigurationDescriptorValue - The desired configuration value (e.g., Notify, Indicate, None).
    Returns
    • An asynchronous operation that returns a Windows.Devices.Bluetooth.GenericAttributeProfile.GattClientCharacteristicConfigurationDescriptorValue representing the result of the operation.

Windows.Devices.Bluetooth.Rfcomm

Provides APIs for classic Bluetooth communication using the RFCOMM protocol.

RfcommDeviceId

Represents a device ID for an RFCOMM service.

Properties

  • string DeviceId { get; }
    Gets the string representation of the RFCOMM device ID.
  • Windows.Devices.Enumeration.DeviceInformation DeviceInfo { get; }
    Gets the DeviceInformation object associated with this RFCOMM device ID.

Methods

  • static Windows.Foundation.IAsyncOperation FromIdAsync(string deviceId)
    Creates an RfcommDeviceId from a device ID string.
    Parameters
    • deviceId: string - The device ID string to parse.
    Returns
    • An asynchronous operation that returns an RfcommDeviceId.

Windows.Devices.Bluetooth.Background

APIs for enabling Bluetooth functionality in background tasks.

Windows.Devices.Bluetooth.DeviceInformation

Provides access to device information for Bluetooth devices.

BluetoothDevice

Represents a Bluetooth device.

Properties

  • string Name { get; }
    Gets the name of the Bluetooth device.
  • BluetoothDeviceId BluetoothDeviceId { get; }
    Gets the unique identifier for the Bluetooth device.
  • Windows.Foundation.Collections.IVectorView Services { get; }
    Gets the collection of GATT services exposed by the device.

Methods

  • static Windows.Foundation.IAsyncOperation FromIdAsync(string deviceId)
    Retrieves a BluetoothDevice object from its device ID.
    Parameters
    • deviceId: string - The device ID of the Bluetooth device.
    Returns
    • An asynchronous operation that returns a BluetoothDevice.
  • static Windows.Foundation.IAsyncOperation GetDeviceSelectorAsync()
    Gets a device selector string that can be used with Windows.Devices.Enumeration.DeviceInformation.FindAllAsync to find Bluetooth devices.
    Returns
    • An asynchronous operation that returns a Windows.Devices.Enumeration.DeviceInformationCollection.