How to Get Heart Beat Rate in Microsoft Band

Create a new Windows Phone project and add the install Microsoft Band SDK and select Manage NuGet Packages as shown in the following screen.

Manage NuGet Packages

Now search for and install the Microsoft Band SDK as in the following screen.

install Microsoft Band SDK

After installing the Microsoft SDK, check that the Proximity capability has been added to the manifest file as in the following:


Enable Proximity

Add the following code to the Package.appmanifest file. Right-click the appmainfest file and select View Code to add the code.

  1. <DeviceCapability Name="bluetooth.rfcomm" xmlns="">  
  2.    <Device Id="any">  
  3.       <Function Type="serviceId:A502CA9A-2BA5-413C-A4E0-13804E47B38F" />  
  4.       <Function Type="serviceId:C742E1A2-6320-5ABC-9643-D206C677E580" />  
  5.    </Device>  
  6. </DeviceCapability>  
The first step is to connect to the Band. To make a connection the band and the device must be paired with the Bluetooth. To get the Band paired and establish a connection use the Band Client Manager. 
  1. Add the namespace.
    1. using Microsoft.Band;  
    2. using Microsoft.Band.Sensors;  
  2. Get the list of paired Bands using the following code.
    1. IBandInfo[] getPairedDevice=await BandClientManager.Instance.GetBandsAsync();  
  3. Connect to the band.
    1. using(IBandClient client=await BandClientManager.Instance.ConnectAsync(getPairedDevice[0]))  
    2. {  
    4. }  
  4. Ensure the user has consented before getting the heart beat rate from the Band.
    1. if(client.SensorManager.HeartRate.GetCurrentUserConsent()!=UserConsent.Granted)  
    2. {  
    3.    await client.SensorManager.HeartRate.RequestUserConsentAsync();  
    4. }  
    Some sensor requires user consent.

    You can request the permission status of the specific sensor.

    The user gives permission once, the application would not need to request it again.
  5. Start the sensor to read the heart beat.
    1. await client.SensorManager.HeartRate.StartReadingsAsync();  
  6. Stop the Sensor.
    1. await client.SensorManager.HeartRate.StopReadingsAsync();  

Similar Articles