Push Notifications in Windows Phone

In my previous posts I’ve referred to the notification system that comes with Windows Phone, specifically in reference to updating the Live Tiles on the Start screen. We’re going to jump in and take a closer look at how the push notification system works and the types of notifications that are available to you. Firstly, there are three types of notifications that your application can make use of:

Toast Notification

If you want to notify the user of an important event within your application you can send a Toast Notification. This notification is made up of two pieces of text that appear as an overlay across whatever application the user is currently in, as shown in Figure 1. The first text, in this case the word “Tile” is bold, whilst the second text is not. The notification area will only show a single line of text so be mindful when deciding what text to include in your toast notification. So that the user can identify which application the notification has come from it is accompanied by the application icon.

WP7 Push Notifications Figure 1

Figure 1

One exception to be aware of is that if the user is actually in the application that the toast notification belongs to, they will not see the notification. Instead an event is raised within the application and it is up to the application to handle the toast notification.

Tile Notification

One of the objectives of the Start screen is to present “glance and go” information to the user about the status of their applications. As discussed in a previous post you can do this with an update schedule for the tile. However, sometimes you want to dynamically update tiles based on an event, rather than being locked into a certain update frequency. To do this you can send a tile notification to the device. This can be used to update the background image, the text and the badge that appears on the tile. Figure 2 and 3 illustrate how the entire tile can be customised by sending through a tile notification.

WP7 Push Notifications Figure 2

Figure 2

In Figure 2 the background has been updated to a dynamically generated tile that shows wind direction and strength over the last two hours. Figure 3 the same tile has been reset back to the default background but the text has been changed and a badge of 5 has been set in the top right corner.

WP7 Push Notifications Figure 3

Figure 3

The badge is typically used to indicate the number of unread or unprocessed items within the application. Setting the badge to 0 will hide the badge completely. You can’t remove the text overlay completely but you can set it to a space (i.e. “ ”) which will achieve the same effect.

Raw Notification

The last type of notification that Windows Phone supports is a Raw Notification. Unlike a Tile or Toast notification there is no associated visual cue or indicator for a Raw Notification. Raw Notifications as you might imagine are used for sending a small amount of data directly into the application. Imagine the scenario where your Windows Phone application calls a web service to start a lengthy batch process. A couple of minutes later, the service sends a Raw Notification to the device indicating that the process has been completed. This is intercepted by the application, which could either trigger some other action within the application or be used to update a status to the user. In order for the Raw Notification to be received, the application does of course need to be running at the time the notification is sent. For this reason Raw Notifications have a somewhat limited value for most applications.

Before I sign off for this post let’s take a look at an overview of how the notification system works by walking through the steps in Figure 4. Everything starts with your application running on the Windows Phone. The application registers with the Microsoft hosted Push Notification Service, which returns a Channel URI. You can think of this as a) a unique identifier for your application running on a specific device and b) as the URI to which anyone can send a message in order for it to be routed as a notification to the specific device.

WP7 Push Notifications Figure 4

Figure 4

Once the Channel URI has been returned to the application running on the Windows Phone in most scenarios the application will need to send the Channel URI to whatever service or application will be generating the notifications. You can think of this as an identification process where the application is saying “Hi, I’m here, here is my Channel URI which you can used to send notifications to me.” What this Notification Source looks like is completely up to you. In most cases it will be a web service that receives the Channel URI and some other identifier (for example the Device ID) to associate with the Channel URI.

To send a notification (tile, toast or raw) to the device, the Notification Source simply has to do a HTTP Post to the corresponding Channel URI. The structure of the message determines what type of notification is sent to the device by the Push Notification Service.

In this post you’ve seen an overview of the Push Notification Service for Windows Phone and the types of notifications that can be sent to the phone. Next up, we’ll be diving in and showing how your application can register for notification and then how you can send notifications by curating the appropriate XML.

Win an Annual Membership to Learnable,

SitePoint's Learning Platform

  • Ben Bonora

    Awesome! I’m very pleased to see that you guys have now included WP7 as part of buildmobile.com site. Say what you will about Microsoft but I really feel like WP7 is a great phone and is underrated. The whole concept of “hubs” is very user friendly intuitive and is at the leading edge of U.

    Microsoft has had some major shortcomings in the past but this not one of them. I really hope that this proves to be successful and that they are able to shed some the negative stigma associated with the company.

    Okay… enough about how much I love my phone. Is there anyway you could do a “hello world” tutorial for wp7? It would be awesome to create my own app for my phone even if just says “hello world” :)

  • http://www.builttoroam.com Nick

    Ben, There are a ton of great resources available on http://create.msdn.com which cover the basics of getting started with WP7 development. Essentially if you download the tools, run Visual Studio, File -> New Project -> Windows Phone Application and press run you’ll have a working application. Of course, you’ll then want to add functionality to the app….

    An alternative you may want to look at is the Social Viewer template (http://socialviewer.codeplex.com) which can be used to build applications that consume data feeds (eg RSS, Atom, Facebook, Twitter, Flickr). You can specify the feeds in the configuration file and you’re basically done. The template was built so that you can either just specify the feeds, or you an get fancy and restyle the layout, customise the lists or consume your own type of data feed.

    Happy WP7’deving