Developing for the Microsoft Band Android Edition

In my last post we looked at getting set up to develop a Windows Phone app using the Microsoft Band SDK as well as Visual Studio Community Edition on a Windows 10 machine. We also looked at using the Web Tiles, which utilizes a web interface to build a communication tile that you install with your Microsoft Health App. In this post, we will look at getting going with Android development.

In order to start development for the Microsoft Band let’s go over some ground rules. You are not building an app for the “Band”. You are building an app for a mobile device (aka Phone) which will take advantage of all of the sensors within the Band. Think of the Band as sending and receiving information. It sends data from it’s sensors and receives data from the app that you create.

There are 2 major aspects of developing for the Band. The “app” and the “Band UI”. The app is something that you have full control over. The UI, the code, the OS (yes, we support Android, iOS and Windows development). The Band UI is more structured and starts with the Tile which is the first interaction with your app. Once the user engages with the Tile, you then can create Pages with information and actions.

Development Setup

To get started with the Microsoft Band development, we will first need to get our machine up and running. Whether you are on Windows or Mac, the steps are pretty much the same.

  1. Download and install Java JDK
  2. Download and install Visual Studio Emulator for Android (Windows) or Xamarin Android Player (Mac)…Visual Studio Emulator for the Mac coming soon.
  3. Download and install Android Studio
  4. Download the Android SDK for Microsoft Band

Once everything is downloaded and installed, you can start by creating an empty Android project.

After the project is created and before you start coding, you will need to make sure we have the Microsoft Band SDK (jar file) added to our project. In Android Studio we can drag our jar file into our lib directory. Once we do that, make sure you right click on the jar file and choose “Add as Library” so it is added to your Gradle and project.

Now you are ready to start development!

Development Process

The process of creating an app and connecting to the band is in 3 steps.

  1. The first step in our app is to make a connection to a Band. To make a connection, the Band and the our Android device must be paired. Item to note – this will not work within the emulator, you will need a device. You can use the Band Client Manager to get a list of paired Bands, and establish a connection to one or more paired Bands.

  2. Once we get a list of paired bands we can then start the process of subscribing to its sensors. The subscriptions are managed by the Band Sensor Manager on the Band Client. For each hardware sensor, the Sensor Manager allows the application developer to create a subscription. A subscription is essentially a platform-specific callback mechanism. It will deliver data at intervals specific to the sensor. Some sensors have dynamic intervals, such as the Accelerometer (on Android and Windows), that allow developers to specify at what rate they want data to be delivered. Other sensors deliver data only as their values change.

    Item to note – sensor subscription can be taxing on battery. Use as needed.
  3. We also then can create a Event Listener to perform our operations.

    Item to note – The Heart Rate sensor requires user consent to access. You can prompt and check if the user provided the appropriate permissions before your calls.

  4. That is basically it. There are some clean up methods such as deregistering the event listeners when done, but more or less those couple of lines will get you up and running.

Take a look at the following Channel 9 Video for more detail on building the full app or the GitHub repo.