Click here to Skip to main content
15,867,889 members
Articles / Mobile Apps
Tip/Trick

Connecting Windows Phone to Band & Creating New Tile on Band

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
27 Oct 2015CPOL1 min read 6.5K   3  
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:

C#
using Microsoft.Band;

Step 2

Get a list of paired Bands:

C#
IBandInfo[]pairedBands = await BandClientManager.Instance.GetBandsAsync();

Step 3

Connect to the Band to get a new BandClient object:

C#
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:

C#
using Microsoft.Band.Tiles;

Step 2

Retrieve the list of your application’s tiles already on the Band:

C#
// 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:

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

Step 4

Create New Style:

C#
// 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.. "+ 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
-- There are no messages in this forum --