Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Connecting Windows Phone to Band & Creating New Tile on Band

0.00/5 (No votes)
27 Oct 2015 1  
This tip gives you details about how to connect Windows Phone to Microsoft Band.

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]))
	{
		// do work after successful connect
	}
}
catch(BandException ex)
{
	// handle a Band connection exception
}

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:

// get the current set of tiles
IEnumerable<BandTile> tiles = await bandClient.TileManager.GetTilesAsync();

Step 3

Determine if there is space for more tiles on the Band:

// determine the number of available tile slots on the Band
int tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();

Step 4

Create New Style:

// create the small and tile icons from writable bitmaps.
// Small icons are 24x24 pixels.
WriteableBitmap smallIconBitmap = new WriteableBitmap(24, 24);
BandIcon smallIcon = smallIconBitmap.ToBandIcon();

// Tile icons are 46x46 pixels for Microsoft Band 1, and 48x48 pixels for Microsoft //Band 2.
WriteableBitmap tileIconBitmap = new WriteableBitmap(46, 46);
BandIcon tileIcon = tileIconBitmap.ToBandIcon();

// create a new Guid for the tile
Guid tileGuid = Guid.NewGuid();

// create a new tile with a new Guid
BandTile tile = new BandTile(tileGuid)
{
	IsBadgingEnabled = true,
	Name = "TileName",
	SmallIcon = smallIcon,
	TileIcon = tileIcon
};
try
{
	// add the tile to the Band
	if (await bandClient.TileManager.AddTileAsync(tile))
	{
		// do work if the tile was successfully created
	}
}
catch (BandException ex)
{
	MessageDialog message = new MessageDialog("Oops.! Something Went Wrong.. &ldquo;+ 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here