doc/articles/features/barometer.md
[!TIP] This article covers Uno-specific information for
Barometer. For a full description of the feature and instructions on using it, see Barometer Class | Microsoft Learn.
Windows.Devices.Sensors.Barometer class allows measuring pressure in hectopascals (hPa).| Feature | Windows | Android | iOS | Web (WASM) | macOS | Linux (Skia) | Win 7 (Skia) |
|---|---|---|---|---|---|---|---|
GetDefault | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
ReadingChanged | ✔ | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ |
ReportInterval | ✔ | ✔ | ✖ | ✖ | ✖ | ✖ | ✖ |
GetDefault method is available on all targets and will return null on those which do not support Barometer or devices that do not have such a sensor.ReadingChanged event when you no longer need the readings, so that the sensor is no longer active to avoid unnecessary battery consumption.var barometer = Barometer.GetDefault();
barometer.ReadingChanged += Barometer_ReadingChanged;
private async void Barometer_ReadingChanged(Barometer sender, BarometerReadingChangedEventArgs args)
{
// If you want to update the UI in some way, ensure the Dispatcher is used,
// as the ReadingChanged event handler does not run on the UI thread.
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
OutputTextBlock.Text = $"Sensor reading in hPa = {args.Reading.StationPressureInHectopascals}, " +
$"timestamp = {args.Reading.Timestamp}";
});
}
barometer.ReadingChanged -= Barometer_ReadingChanged;