First steps with Xamarin and the Microsoft Band SDK

Last Saturday my Microsoft Band 2 was finally delievered to me, I preordered it at Amazon.co.uk on the time it was presented in NY. Till today I do not see a way to get in Austria on another way, very unfortunate – it’s a really nice piece of tech.

Normally one would think the first think to do with it, is to go out for run, but wait – there is a Band SDK out for Xamarin already.
So I finished up the hole weekend to mess around with it and on my second weekend I thought about wrtiting a few things down, so here we go with the first part.

I want to start with a quick Hello World (Surprise!) Android app.

Prerequisites

Before we can start with the code, we have to get a few things frist.

Setup

Create a new Project

Xamarim Microsoft Band First Steps New Proect

and add the downloaded *.DLLs to the references.

Xamarim Microsoft Band Add DLLs

Next we want to make sure that we allow our application to use bluetooth and also the permission to use the Microsoft Band service. For this purpose add the following lines to the AssemblyInfo.cs (Project -> Properties in VS Solution Explorer)

Connect to the Band

To connect to the Band create a new class with the code below or use the code inside the PairBand() method.

We get the BandClientManager instance here, call for all connected Bands and (assuming you have only one Band) connect to the first one we have found.

Next we want to change the MainActivity.cs a little bit, so we can actually see if we are connected to the Band. For this purpose we will modify the button click event.
If we click on the button in our app later, it will show the name of the connected device.

Result

Note: The Android emulator does not support Bluetooth, so you will get an exception when execute your project. Instead of using the emulator you should plug in your phone.
If everything worked out, you should see something like this on your device:
Xamarim Microsoft Band Android App Xamarim Microsoft Band Android App

The complete project can be found on Github – Complete Xamarin Band Android Hello World Projectas well.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *