First impression of Microsoft Band – developing


The Band SDK was made available last week and now we will see what we can do. First the SDK is really a nuget package which makes it super easy to use and install. There are also a SDK for Android and iOS is coming soon according to the Band SDK home page (

There are also sample code which after a first glance demos all of the Bands functionality.

First I made a Universal app and put the nuget package in both projects. This however did not work. The Windows version doesn’t compile. I seems it looks in the wrong directory when looking for its files. I copied Microsoft.Band.Store catalog to another place to make it compile. You also need to add the bluetooth capability to the windows project appxmanifest like so:

  <Capability Name="internetClientServer" />
  <DeviceCapability Name="bluetooth.rfcomm" xmlns="">
    <Device Id="any">
      <!-- Used by the Microsoft Band SDK Preview -->
      <Function Type="serviceId:A502CA9A-2BA5-413C-A4E0-13804E47B38F" />
      <!-- Used by the Microsoft Band SDK Preview -->
      <Function Type="serviceId:C742E1A2-6320-5ABC-9643-D206C677E580" />

For phone this is added when you add the nuget package. But when I started to develop it can’t find the BandClientManager, its there for the phone but not the windows project. You need this to connect so for now only phone works, at least I couldn’t find any way to get it to work. If you can please share in the comments below. But since this is a preview hopefully the issues will be solved later on.


Lets start and see how we can get hold of the sensor data and what data we can get. There are eight sensors in the SDK:









and the are all easy to access. The code is quite simple.

var pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Length < 1)
    // display some error message

_bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]);

_bandClient.SensorManager.Accelerometer.ReadingChanged += Accelerometer_ReadingChanged;
await _bandClient.SensorManager.Accelerometer.StartReadingsAsync();

_bandClient.SensorManager.Distance.ReadingChanged += DistanceOnReadingChanged;
await _bandClient.SensorManager.Distance.StartReadingsAsync();

_bandClient.SensorManager.Gyroscope.ReadingChanged += GyroscopeOnReadingChanged;
await _bandClient.SensorManager.Gyroscope.StartReadingsAsync();

_bandClient.SensorManager.HeartRate.ReadingChanged += HeartRateOnReadingChanged;
await _bandClient.SensorManager.HeartRate.StartReadingsAsync();

_bandClient.SensorManager.Pedometer.ReadingChanged += PedometerOnReadingChanged;
await _bandClient.SensorManager.Pedometer.StartReadingsAsync();

_bandClient.SensorManager.SkinTemperature.ReadingChanged += SkinTemperatureOnReadingChanged;
await _bandClient.SensorManager.SkinTemperature.StartReadingsAsync();

_bandClient.SensorManager.Ultraviolet.ReadingChanged += UltravioletOnReadingChanged;
await _bandClient.SensorManager.Ultraviolet.StartReadingsAsync();

_bandClient.SensorManager.Contact.ReadingChanged += ContactOnReadingChanged;
await _bandClient.SensorManager.Contact.StartReadingsAsync();

After all ReadingChanged are hooked up this is how one retrieves data from the sensors.

private async void ContactOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("exp = {0}", read.State);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { ContactTextBlock.Text = text; }).AsTask();

private async void UltravioletOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("exp = {0}", read.ExposureLevel);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { UVTextBlock.Text = text; }).AsTask();

private async void SkinTemperatureOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("temp = {0}", read.Temperature);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SkinTextBlock.Text = text; }).AsTask();

private async void PedometerOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("steps = {0}", read.TotalSteps);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { PedoTextBlock.Text = text; }).AsTask();

private async void HeartRateOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("heart = {0}\nquality = {1}", read.HeartRate, read.Quality);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { HeartTextBlock.Text = text; }).AsTask();

private async void GyroscopeOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("X = {0}\nY = {1}\nZ = {2}\naX = {3}\naY = {4}\naZ = {5}", read.AccelerationX, read.AccelerationY, read.AccelerationZ, read.AngularVelocityX, read.AngularVelocityY, read.AngularVelocityZ);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { GyroTextBlock.Text = text; }).AsTask();

private async void DistanceOnReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("pace = {0}\nspeed = {1}\nmotion = {2}\ndist = {3}", read.Pace, read.Speed, read.CurrentMotion, read.TotalDistance);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { DistTextBlock.Text = text; }).AsTask();

private async void Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs e)
    var read = e.SensorReading;
    var text = string.Format("X = {0}\nY = {1}\nZ = {2}", read.AccelerationX, read.AccelerationY, read.AccelerationZ);
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { AccTextBlock.Text = text; }).AsTask();

In my example all I’m doing is displaying data on the screen but one can of course do something exciting with it.

And after the app is done reading one calls StopReadingsAsync for the sensors you don’t want any more data from.

await _bandClient.SensorManager.Accelerometer.StopReadingsAsync();
await _bandClient.SensorManager.Distance.StopReadingsAsync();
await _bandClient.SensorManager.Gyroscope.StopReadingsAsync();
await _bandClient.SensorManager.HeartRate.StopReadingsAsync();
await _bandClient.SensorManager.Pedometer.StopReadingsAsync();
await _bandClient.SensorManager.SkinTemperature.StopReadingsAsync();
await _bandClient.SensorManager.Ultraviolet.StopReadingsAsync();

Send data to the Band


Now that we can get data from Band how do we send data to it? We start by making it vibrate.

//NotificationOneTone = 0,
//NotificationTwoTone = 1,
//NotificationAlarm = 2,
//NotificationTimer = 3,
//OneToneHigh = 4,
//TwoToneHigh = 5,
//ThreeToneHigh = 6,
//RampUp = 7,
//RampDown = 8,

await _bandClient.NotificationManager.VibrateAsync(VibrationType.NotificationOneTone);

very easy indeed.

Add/remove tile

This is the code to add a tile

var remaining = await _bandClient.TileManager.GetRemainingTileCapacityAsync();
if (remaining == 0)
    // error message

// Create a Tile.
var myTileId = Guid.NewGuid();
var myTile = new BandTile(myTileId)
    Name = "My Tile",
    TileIcon = await LoadIcon("ms-appx:///Assets/Large.png"),
    SmallIcon = await LoadIcon("ms-appx:///Assets/Small.png")
await _bandClient.TileManager.AddTileAsync(myTile);

The LoadIcon function is a must since the icon must be of BandIcon type. I have taken the function straight from the sample code.

private static async Task LoadIcon(string uri)
    var imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(uri));

    using (var fileStream = await imageFile.OpenAsync(FileAccessMode.Read))
        var bitmap = new WriteableBitmap(1, 1);
        await bitmap.SetSourceAsync(fileStream);
        return bitmap.ToBandIcon();

And if you for some reason want to remove the tile you run this code

var tiles = await _bandClient.TileManager.GetTilesAsync();
foreach (var tile in tiles)
    await _bandClient.TileManager.RemoveTileAsync(tile);                    

Sending data to the tile

You can send a “toast” to the Band after you have your tile on it.

await _bandClient.NotificationManager.ShowDialogAsync(tileId, "Hello", "Hello world!");

This shows up on the band and after it is dismissed its gone. If you want the toast but still want the info be available when you click the tile, you send

await _bandClient.NotificationManager.SendMessageAsync(tileId, "Hello", "Hello World!", DateTimeOffset.Now, MessageFlags.ShowDialog);

And if you only want the text on the tile but not showing a toast, you send

await _bandClient.NotificationManager.SendMessageAsync(tileId, "Hello", "Hello World!", DateTimeOffset.Now, MessageFlags.None);

Change color and background image

There are also a possibility to change the color and the background image of the Band. I not sure why one want a app to change this since this is something you set to fit your personality. You can for example don´t change the phone color from apps, you can get the selected color but don’t change it.


Its quite easy to get and set data from the Band. If you have an app that people open often to see short info you should definitely create a tile for the Band and send data  to it. I haven’t done any analysis of the sensor data you get from the app (perhaps another blog in the future) but there are many possibilities for what one can do with this. So just code away and either make your app use the Band for showing info or make use of the sensor data you can get from it.

This Post Has 3 Comments

  1. Jim

    I can confirm that bit of xml for the capabilities node is required for phone app as well, if I do not include it then the code gets an exception at the ‘ConnectAsync’ line and returns an exception message of ‘Service’. Your post did the trick for me, thank you!

  2. Gabriel

    Have you tried playing around with layouts and buttons? I’ve managed to create a button but I’m getting issues with the event handlers. They don’t seem to get called. I’m using info in latest SDK doco.

  3. Gabriel

    Hi. Have you managed to get buttons to work with the updated SDK?

Leave a Reply