GATT Scenario: Control Presentation of Bluetooth LE Device Data
Language: HTML | XAML

GATT Scenario: Control Presentation of Bluetooth LE Device Data(XAML)

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

A Windows Store App Bluetooth LE devices may expose a battery service that provides the current battery level to the user. The battery service includes an optional PresentationFormat descriptor which allows some flexibility in interpretation of the battery level data. This scenario provides example of an App that works with such a device and uses the PresentationFormats property to format a characteristic value, before presenting it to the user.

async void Initialize()
    var batteryServices = await Windows.Devices.Enumeration

    if (batteryServices.Count > 0)
        // Use the first Battery service on the system
        GattDeviceService batteryService = await GattDeviceService

        // Use the first Characteristic of that Service
        GattCharacteristic batteryLevelCharacteristic =

        batteryLevelCharacteristic.ValueChanged += batteryLevelChanged;
        statusTextBlock.Text = "No Battery services found !";

void batteryLevelChanged(
    GattCharacteristic sender,
    GattValueChangedEventArgs eventArgs)
    byte levelData = Windows.Storage.Streams.DataReader

    double levelValue;

    if (sender.PresentationFormats.Count > 0)
        levelValue = levelData * 
            Math.Pow(10.0, sender.PresentationFormats[0].Exponent);
        levelValue = (double)levelData;

    batteryLevelTextBlock.Text = levelValue.ToString();



© 2017 Microsoft