Quick Start
Prerequisites
In order to develop applications that use the SensorCore SDK, you will need either Visual Studio 2013 or Visual Studio 2015 with Windows Phone 8.1 SDK or Windows 10 SDK installed.
The SDK supports emulator target with the simulator classes but with greatly reduced functionality, so in practice, you will also need a developer unlocked device that supports SensorCore SDK.
Lumia devices previous to WP 8.1 and Cyan SW update do not support SensorCore.
Getting started
As our first project, we will be creating a simple application that displays the current Step Counter values.
Create a new project
Start by opening Visual Studio and creating a new Visual C# Windows Universal project.
- Select File > New > Project ...
- Select Templates > Visual C# > Windows > Windows Universal > Blank App (Windows Universal) and give the name of the project as "HelloSensorCore".
Add the SensorCore SDK to the project
The next step is to include the SensorCore SDK in the project. The packages are in the NuGet format.
Now, we can add the actual NuGet package to the project.
- Select Tools > NuGet Package Manager > Manage NuGet Packages for Solution...
- Locate Lumia SensorCore SDK and click Install.
- When prompted to select projects, make sure our project is checked and click OK.
- Read the license terms and click OK.
- You can now close the package manager window.
- If prompted to reload project files, click Reload All.
About to install SensorCore SDK to our project
In order for an application to access the APIs, you need to declare the SensorCore HID device and Location capability in the application's Package.appxmanifest:
<DeviceCapability Name="location" /> <DeviceCapability Name="humaninterfacedevice"> <Device Id="vidpid:0421 0716"> <Function Type="usage:ffaa 0001" /> <Function Type="usage:ffee 0001" /> <Function Type="usage:ffee 0002" /> <Function Type="usage:ffee 0003" /> <Function Type="usage:ffee 0004" /> </Device> </DeviceCapability>
Using the SensorCore SDK in code
In this example code, we will show how to implement a simple application that shows the walking and running steps for today.
Let's define a UI element to receive all our information from the screen. Open MainPage.xaml, and inside the <Grid\> element, add a ListBox:
<Grid>
<ListBox x:Name="SensorcoreList"/>
</Grid>
Now, we are ready for some coding! Add the following "using" statements to MainPage.xaml.cs:
using Windows.UI.Popups; using System.Threading.Tasks; using Lumia.Sense;
Add the following member variable to the MainPage class:
private StepCounter _stepCounter;
First, you should check if the device supports step counting. You can do this by using the StepCounter.IsSupportedAsync() method. However, starting in Windows 10, for SensorCore APIs to work at all, the user is required to give the calling application permission to use location information and have the system location setting enabled. It is possible that calling IsSupportedAsync() will fail with an exception to indicate that location has been disabled. Therefore, it is generally easier to just try and instantiate the sensor directly using the GetDefaultAsync() method as it will also throw exceptions if the device doesn't support SensorCore or if location settings are not enabled.
Add the following code to the MainPage constructor to initialize the step counter and handle the activation/deactivation of the sensor according to the visibility of the app.
Window.Current.VisibilityChanged += async ( oo, ee ) => { if( ee.Visible ) { if( await CallSensorcoreApiAsync( async () => { if( _stepCounter == null ) { _stepCounter = await StepCounter.GetDefaultAsync(); } else { await _stepCounter.ActivateAsync(); } } ) ) { await ShowCurrentReadingAsync(); } } else { if( _stepCounter != null ) { await CallSensorcoreApiAsync( async () => await _stepCounter.DeactivateAsync() ); } } };
To handle the exceptions, add the following wrapper function to the MainPage class:
/// <summary> /// Calls given function and handles any SensorCore exceptions. /// </summary> /// <param name="action">Function to call</param> /// <returns><c>true</c> if the call was successful, <c>false</c> otherwise</returns> private async Task<bool> CallSensorcoreApiAsync( Func<Task> action ) { Exception failure = null; try { await action(); } catch( Exception e ) { failure = e; } if( failure != null ) { MessageDialog dialog; switch( SenseHelper.GetSenseError( failure.HResult ) ) { case SenseError.LocationDisabled: dialog = new MessageDialog( "Location has been disabled. Do you want to open Location settings now?", "Information" ); dialog.Commands.Add( new UICommand( "Yes", async cmd => await SenseHelper.LaunchLocationSettingsAsync() ) ); dialog.Commands.Add( new UICommand( "No" ) ); await dialog.ShowAsync(); return false; case SenseError.SenseDisabled: { dialog = new MessageDialog( "Places visited has been disabled in Lumia motion data settings. Do you want to open settings now?", "Information" ); dialog.Commands.Add( new UICommand( "Yes", new UICommandInvokedHandler( async ( cmd ) => await SenseHelper.LaunchSenseSettingsAsync() ) ) ); dialog.Commands.Add( new UICommand( "No" ) ); await dialog.ShowAsync(); return false; } default: dialog = new MessageDialog( "Failure: " + SenseHelper.GetSenseError( failure.HResult ), "" ); await dialog.ShowAsync(); return false; } } return true; }
After that, we are ready to add the code to access the step counter. We get the current reading from the sensor and show it in the list box defined in the first step.
private async Task ShowCurrentReadingAsync() { await CallSensorcoreApiAsync( async () => { var reading = await _stepCounter.GetStepCountForRangeAsync( DateTime.Now.Date, TimeSpan.FromDays( 1 ) ); SensorcoreList.Items.Add( "Step counter stats for today" ); if( reading != null ) { SensorcoreList.Items.Add( "Walk steps = " + reading.WalkingStepCount ); SensorcoreList.Items.Add( "Walk time = " + reading.WalkTime.ToString() ); SensorcoreList.Items.Add( "Run steps = " + reading.RunningStepCount ); SensorcoreList.Items.Add( "Run time = " + reading.RunTime.ToString() ); } else { SensorcoreList.Items.Add( "Data not available" ); } } ); }
Deploy your app
Now, make sure that your phone is connected to the PC, and Device build target and ARM architecture are selected from the Visual Studio toolbar.
Deploy your application by selecting Build > Deploy HelloSensorCore.

Our application running on device
Congratulations! You have now successfully built your first SensorCore SDK application.
Downloads
Quickstart project | v1.2.0.0 | HelloSensorCore_uwp.1.2.0.0.zip |