In Windows 10, we are very excited to introduce several APIs for contextual sensing that can help you build apps to improve your customersí daily lives. These include apps that detect presence when customers approach their devices, apps that can detect whether your customer is walking or driving, apps that can help customers track their fitness routines, and more. Using these APIs you can anticipate customersí needs and proactively deliver targeted, personalized, and relevant content or services to enhance and simplify their lives. It is very powerful both in Consumer and Enterprise scenarios.



Detecting activities


We are very happy to introduce the new Activity Detection APIs, which will help detect the userís motion context. These APIs attempt to detect activity states based on current motion of your customer, such as Walking, Running, In Vehicle, Biking, Stationary, and Idle. The Stationary state is returned when a user has the device with them, while the Idle state is returned when the user has the device laying idle on a table or still surface. You also have the ability to create background triggers and get history details for up to 30 days.

A few usage scenarios are:

  • Surface information based on the userís motion context (such as an activity-based playlist)
  • Change the app behavior based on the userís motion context (such as auto-adjusting the camera focus when you detect that the user is capturing an image while walking or running)
  • Health and fitness tracking
  • Navigation and maps
  • Power saving (fpr example, avoiding constantly polling location or wifi when the device os idle or stationary)

The API pattern is shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Getting the current activity
var reading = await activitySensor.GetCurrentReadingAsync();

// Subscribing to activity changes
activitySensor.ReadingChanged += new TypedEventHandler<ActivitySensor,
ActivitySensorReadingChangedEventArgs>(ReadingChanged);

// Getting history of up to 30 days
DateTimeOffset yesterday = ...
var history = await ActivitySensor.GetSystemHistoryAsync(yesterday);
foreach (var entry in history) { ... }

// Using a background task
var trigger = new
Windows.ApplicationModel.Background.ActivitySensorTrigger(reportIntervalMs);
trigger.SubscribedActivities.Add(ActivityType.InVehicle);

// .. register the trigger, etc..


More detailed API reference for activity detection can be found here and UWP SDK Samples can be found here.
Counting steps

Another new addition is the pedometer which counts the userís steps both when walking and running. As with activity detection, you can access history details for up to 30 days.

A typical application would be health and fitness tracking (without requiring an additional gadget/ wearable device). The pedometer can also combine with the wearable and Windows device sensor data.

The API pattern is shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
//Getting the pedometer reading changes
pedometer.ReadingChanged += new TypedEventHandler<Pedometer,
PedometerReadingChangedEventArgs>(ReadingChanged);

void ReadingChanged(Pedometer sender, PedometerReadingChangedEventArgs args)
{
PedometerReading reading = args.Reading;
if (reading.StepKind == PedometerStepKind.Walking)
walkingSteps = reading.CumulativeSteps;
}

//Getting pedometer step count history
var history = await Pedometer.GetSystemHistoryAsync(yesterday);


More detailed API reference for edometer can be found here and UWP SDK Samples can be found here.

Barometer and altitude sensing

We are very happy to introduce the Barometer API that reports barometric station pressure, and the Altimeter API to report altitude and changes in elevation.

Typical applications include:

  • Health and fitness tracking: knowing the altitude, you can determine if the user is going up or down and adjust calorie expenditure calculations accordingly
  • Detect what floor the user is on for indoor navigation
  • Weather forecasting

The API pattern is shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Barometer barometer = Barometer.GetDefault();
BarometerReading reading = barometer.GetCurrentReading();

double pressure = reading.StationPressureInHectopascals;
barometer.ReadingChanged += ...

Altimeter altimeter = Altimeter.GetDefault();
AltimeterReading altimeterReading = altimeter.GetCurrentReading();

double altitudeChange = altimeterReading.AltitudeChangeInMeters;
altimeter.ReadingChanged += ...

//Selecting a report interval
mySensor.ReportInterval = 500;


Detailed API reference for Barometer can be found here and UWP SDK Samples can be found here. Detailed API reference for Altimeter can be found here and UWP SDK Samples can be found here.

Detecting presence

We now support APIs for both short range and long range presence detection. Short range sensors can detect for up to 2-3cm, while some of the longer presence sensors can detect presence up to a 12 meter range.

A few usage scenarios are:

  • Enabling a device to wake on user approach or log off when the user has departed. The Surface Hub uses these APIs to wake on approach when a user walks into a conference room and log off when they depart.
  • Automatic turn off of the display during a phone call
  • Understand and ignore accidental clicks when it is detected that the device is in the userís pocket
  • Detection of gestures

The API pattern using Proximity is as shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using Windows.Devices.Sensors;

//Getting the current reading
ProximitySensorReading reading = sensor.GetCurrentReading();
bool isDetected = reading.IsDetected;

//Subscribing to reading changes
sensor.ReadingChanged += ReadingChanged;
void ReadingChanged(ProximitySensor s, ProximitySensorReadingChangedEventArgs e)
{
ProximitySensorReading reading = e.Reading;
bool isDetected = reading.isDetected
}

//Selecting a report interval
mySensor.ReportInterval = 500;


More detailed API reference for Proximity can be found here and UWP SDK Samples can be found here.
Stay tuned; we will be sharing more details of new Windows 10 features upcoming blog posts. You can also find more information in our Build 2015 session on building contextually-aware UWP apps using sensors.

Source: Contextual sensing in Windows 10 | Building Apps for Windows