Future Strategy for Contextual Sensing

Windows

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

Hello, I’m Rinku Sreedhar, Program Manager for Windows Contextual Sensing and this blog post will cover the following topics:

1. Contextual Sensing APIs and SensorCore APIs
2. New Motion Setting for Activities and Pedometer
3. Checking Apps Access to the Sensors

Contextual Sensing APIs and SensorCore APIs


We hope you are as excited as we are about the new
Please, Log in or Register to view URLs content!
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
Please, Log in or Register to view URLs content!
. I also talked about this at Build 2016 in my session ‘
Please, Log in or Register to view URLs content!
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.
  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.
  3. Our recommendation is that you start using the new Universal Windows Contextual Sensing APIs for
    Please, Log in or Register to view URLs content!
    and
    Please, Log in or Register to view URLs content!
    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.

Please, Log in or Register to view URLs content!


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:

Please, Log in or Register to view URLs content!


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.




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);
}




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.




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);

. . .
});
}
}




In addition to this, if you are interested in learning more about the new Windows 10 Sensor features, please check out the
Please, Log in or Register to view URLs content!
. If you find bugs or issues, please leverage the Windows Feedback tool or
Please, Log in or Register to view URLs content!
. If you would like us to add any new features, please submit them over at
Please, Log in or Register to view URLs content!
or provide as comments below.

Please, Log in or Register to view URLs content!
 

Users who are viewing this thread

Top