Install-Package Microsoft.Band -Pre
Doing this will get you set-up and ready to start developing for the Microsoft Band as is expected. One thing it does for you that you’ll need to know if you don’t install the package through Nuget is that it adds a DeviceCapability into your Package.appxmanifest file which enables the Bluetooth capabilities for the Band which is as follows:
<DeviceCapability Name="bluetooth.rfcomm" xmlns="http://schemas.microsoft.com/appx/2013/manifest"> <Device Id="any"> <!-- Used by the Microsoft Band SDK Preview --> <Function /> <!-- Used by the Microsoft Band SDK Preview --> <Function /> </Device> </DeviceCapability>
Getting connected
Before we get you connecting your app to your Band, you’ll first need to pair the device with your phone (which you’ll probably have done if you’re using the Band on a day-to-day basis).
To get yourself going, you’ll want to add Microsoft.Band using directive to your class. From there you can using the BandClientManager to get a list of the paired bands with the phone the app will be running on. You’ll do this as follows:
var bandInfo = (await BandClientManager.Instance.GetBandsAsync()).FirstOrDefault();
You’ll most likely only have one Band connected to your device for calling FirstOrDefault from the System.Linq namespace will return your the first device in the array that is returned from the GetBandsAsync method. If no device is connected, it will return null which you’ll have to handle in your application.
Now that you hold a reference to your Band, you’ll want to get yourself connected which is as simple as using the BandClientManager. You’ll do that as follows:
try { using (var bandClient = await BandClientManager.Instance.ConnectAsync(bandInfo)) { } } catch (BandException be) { }
While it is possible that your device is connected to your phone, there will be occasions when the user is not with their mobile device and the Band becomes disconnected. You’ll have to handle that in your application as shown above.
References: http://jamescroft.co.uk/blog/wearable/developing-for-microsoft-band-with-winrt-getting-connected/