Introduction
Connecting Windows Phone to Band by using simple steps. Also the tip says about creating tile on Microsoft Band.
Using the Code
The first step in using the SDK is to make a connection to a Band. To make a connection, the Band and the device that your application is running on must be paired with each other. You can use the Band Client Manager to get a list of paired Bands, and establish a connection to one or more paired Bands. Operations to the Band are encapsulated in a Band Client.
The following are steps to connect band with Windows Phone:
Step 1
Set up using directives:
using Microsoft.Band;
Step 2
Get a list of paired Bands:
IBandInfo[]pairedBands = await BandClientManager.Instance.GetBandsAsync();
Step 3
Connect to the Band to get a new BandClient
object:
try
{
using(IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
}
}
catch(BandException ex)
{
}
Creating Tile on Microsoft Band
The tile can include an icon (46x46 pixels for Microsoft Band 1, 48x48 pixels for Microsoft Band 2), a small icon (24x24 pixels), and a title or name for the tile. All tiles will use the theme colours of the Band. Using the Tile Manager, the developer can override that theme.
Note: For creating Tile, we are using Button_Click
event handling.
Step 1
Update using
directives:
using Microsoft.Band.Tiles;
Step 2
Retrieve the list of your application’s tiles already on the Band:
IEnumerable<BandTile> tiles = await bandClient.TileManager.GetTilesAsync();
Step 3
Determine if there is space for more tiles on the Band:
int tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();
Step 4
Create New Style:
WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
BandIcon smallIcon = smallIconBitmap.ToBandIcon();
WriteableBitmap tileIconBitmap = new WriteableBitmap(46, 46);
BandIcon tileIcon = tileIconBitmap.ToBandIcon();
Guid tileGuid = Guid.NewGuid();
BandTile tile = new BandTile(tileGuid)
{
IsBadgingEnabled = true,
Name = "TileName",
SmallIcon = smallIcon,
TileIcon = tileIcon
};
try
{
if (await bandClient.TileManager.AddTileAsync(tile))
{
}
}
catch (BandException ex)
{
MessageDialog message = new MessageDialog("Oops.! Something Went Wrong.. “+ ex.Message);
message.ShowAsync();
}
Points of Interest
By this example, I learned demonstration of Windows Phone Connection with Microsoft Band and how to create Tile on the Band by using some cool steps.