Skip to main content
June 3, 2016
Mobile

Future Strategy for Contextual Sensing



Written by Rinku Sreedhar, Program Manager for Windows Contextual Sensing.

We hope you are as excited as we are about the new Contextual Sensing APIs in Windows 10. We introduced multiple new Sensor APIs that will let you enable contextual awareness in your apps.

I have received several questions on what is our strategy with these APIs, and how does it relate to the Lumia Sensorcore APIs. I also talked about this at Build 2016 in my session ‘What’s new with Contextual Sensing’  and I’m hoping this blog will clarify all the questions you have.

A few key points to note:

  1. Lumia SensorCore SDK are gradually being merged into the Windows 10 APIs. We now support the contextual sensing features like Activity Detection and Pedometer as part of Windows. These new APIs are supported on new hardware with Windows 10, which has the required sensors and drivers.
  2. Activity Monitor and Step Counter APIs in the Microsoft Lumia SensorCore SDK has been deprecated. What this means is we will no longer offer support or continue to develop these APIs in future. However, Sensorcore APIs and the apps built using these APIs will continue to work on pre-Windows 10 devices, which have the required sensors.
  3. Our recommendation is that you start using the new Universal Windows Contextual Sensing APIs for Activity Detection and Pedometer which replaced the Activity Monitor and Step Counter APIs in the Microsoft Lumia SensorCore SDK.
  4. Please do check out the updated Sample apps for Activities and Steps below:

These are updated SensorCore samples, which show the usage of the new UWP APIs in addition to the Sensorcore APIs.

In case you need any help porting your applications, or you have any questions, please do provide your comments and let me know.

New Motion Setting for Activities and Pedometer

Related to this, I also want to provide some information about the new Settings for Activity and Pedometer. Activity Detection tracks users’ current activity states like walking, running, biking, stationary, driving etc., while Pedometer tracks the users’ running and walking step counts and the duration of time when the user is active. Although these features do not collect personally identifiable data, some users may prefer not to make this information available to apps.

Windows 10 adds a new Privacy Setting for Motion data.  This is in the Settings app (Settings>Privacy>Motion) and will be displayed on devices which has Activity Detection/ Pedometer sensors.  Activity Detection and Pedometer are always ON by default, which means that activities and step counts will be tracked, with data collection enabled.  Users can disable Motion data collection through the Motion Privacy Settings.

The following screenshot shows the Settings app and where you can find the Motion Settings.

1_contextualsensing

Once the users are at the Motion Privacy Settings page, they have multiple options to control their Settings.

  1. Enable/ Disable Motion Data: Motion data collection including History will be ON by default. Users can continue to allow Windows and apps to use the Motion data by leaving the Settings ON or they can turn it OFF.
  2. Clear History: Users can decide to clear the history data. Any Motion data that has been collected will be erased from the system.
  3. Enable/ Disable Motion data for each app: We are also providing per-app Motion ON/OFF toggle which will appear in the Motion Setting page to allow users to control permission to their motion data for a particular app. Any apps that declare the Motion capability will automatically appear in this list.

The next screenshot shows the Motion Setting page and its privacy controls:

2_contextualsensing

Checking your App’s access to Motion Sensors

The following section shows how, as a developer, you can check if the user has given permission for your app to access their Motion data. We will demonstrate how to do this for Activity Detection. A similar approach can be used for Pedometer.

There are two scenarios for checking’s the privacy controls.  Both scenarios use the Windows.Devices.Enumeration.DeviceAccessInformation API.

  1. Checking if the app has access to Activity Detection or Pedometers
  2. Subscribing to be notified of access changes (e.g. if the user switches the privacy toggles from ON to OFF, or vice versa)

Scenario 1: Checking if the app has access to Motion Sensors

The following C# snippet shows how to use the Windows.Devices.Enumeration.DeviceAccessInformation’s CurrentStatus property to check if the app is allowed to access Activity Detection.  Refer to the references section for the links to the complete samples.

[code language=”csharp”]

using Windows.Devices.Enumeration;
using Windows.Devices.Sensors;

// Common class ID for activity sensors.
Guid ActivitySensorClassId = new Guid("9D9E0118-1807-4F2E-96E4-2CE57142E196");

// Determine if the user has allowed access to activity sensors
var deviceAccessInfo = DeviceAccessInformation.CreateFromDeviceClassId(ActivitySensorClassId);
if (deviceAccessInfo.CurrentStatus == DeviceAccessStatus.Allowed)
{
// Get the default sensor
var activitySensor = await ActivitySensor.GetDefaultAsync();
if (activitySensor != null)
{
// Use the sensor

}
else
{
rootPage.NotifyUser("No activity sensor found", NotifyType.ErrorMessage);
}
}
else
{
rootPage.NotifyUser("Access denied to activity sensors", NotifyType.ErrorMessage);
}

[/code]

Scenario 2: Subscribing to be notified of access changes

The following C# snippet shows how to subscribe to the  Windows.Devices.Enumeration.DeviceAccessInformation’s AccessChanged event to notified of access changes. Refer to the references section for links to the complete samples.

[code language=”csharp”]

using Windows.Devices.Enumeration;
using Windows.Devices.Sensors;

// Common class ID for activity sensors
Guid ActivitySensorClassId = new Guid("9D9E0118-1807-4F2E-96E4-2CE57142E196");

private DeviceAccessInformation _deviceAccessInformation;

public Scenario3_ChangeEvents()
{

// Register for access changed notifications for activity sensors
_deviceAccessInformation = DeviceAccessInformation.CreateFromDeviceClassId(ActivitySensorClassId);

_deviceAccessInformation.AccessChanged += new TypedEventHandler<DeviceAccessInformation, DeviceAccessChangedEventArgs>(AccessChanged);
}

/// <summary>
/// This is the event handler for AccessChanged events.
private async void AccessChanged(DeviceAccessInformation sender,
DeviceAccessChangedEventArgs e)
{
var status = e.Status;
if (status != DeviceAccessStatus.Allowed)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootPage.NotifyUser("Access denied to activity sensors",
NotifyType.ErrorMessage);

. . .
});
}
}

[/code]

In addition to this, if you are interested in learning more about the new Windows 10 Sensor features, please check out the Build 2016 session on sensors. If you find bugs or issues, please leverage the Windows Feedback tool or MSDN forums.  If you would like us to add any new features, please submit them over at UserVoice or provide as comments below.