Nick's .NET Travels

Continually looking for the yellow brick road so I can catch me a wizard....

Windows Phone Mango Push Notification Changes

The basic concept of push notifications for Windows Phone doesn’t change for Mango. There are still three types (Push Notifications in Windows Phone), tile, toast and raw, and your application still needs to register with the Microsoft Push Notification Service in order to make use of this feature. The differences are that there are extensions to the service, which both plug holes in the initial implementation and provide support for multiple tiles and the back of tiles. Let’s go through the different types of notifications and I’ll point out some of the differences.

Toast Notifications

One of the issues with toast notifications in WP7 was that when the user clicked on the toast they were taken into the application as if they’d clicked on the application from the apps list. There was no arguments or information passed into the application to indicate where it had been launched from. This made it rather painful to do anything useful with toast notifications, other than trying to encourage users back into the application.

In Mango there is an additional (optional) Param element that can be specified in the toast message payload. This is essentially a navigation uri, or a query string, that is passed into the application. The payload message structure looks similar to the following:

string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                              "<wp:Notification xmlns:wp=\"WPNotification\">" + 
                                                  "<wp:Toast>" +
                                                      "<wp:Text1>First String</wp:Text1>" +
                                                      "<wp:Text2>Second String</wp:Text2>" + 
                                                      "<wp:Param>/PageTwo.xaml</wp:Param>" + 
 
                                                 "</wp:Toast>" + 
                                              "</wp:Notification>";

The bold line illustrates the new Param element. In this case if the user taps on this toast, they will be taken directly to PageTwo.xaml. Note that PageTwo.xaml will be the first page in the back stack, bypassing the normal entry point for the application.

The Param element can include a query string either in addition to, or instead of, a navigation uri. For example:

     /PageTwo.xaml?query1=value1
     ?query2=value2

In both cases the query key-value pairs can be extracted via the NavigationContext for the page that is navigated to. In the first case, this would be PageTwo.xaml, whereas in the second (where there is no page defined in the Param element) the page would be the default launch page for the application.

 

Tile Notifications

Live tiles get a major uplift in Mango. You still of course have the front tile which consists of the background image, a badge/count in the top right corner and the title. With Mango you can use the back of the tile as well. The back of the tile also has a background image and a title but also has a content attribute which can be used to display more text content (you can’t modify the font size or layout though). If that wasn’t enough, Mango also gives you the ability to pin multiple tiles for your application to the Start (in much the same way as web pages and contacts can be pinned to the Start today).

The new message structure for sending a tile notification is:

string tileMessage =     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                          "<wp:Notification xmlns:wp=\"WPNotification\">" +
                                              "<wp:Tile Id=\"{0}\">" +
                                                  "<wp:BackgroundImage>Background.png</wp:BackgroundImage>" +
                                                  "<wp:Count>6</wp:Count>" + 
                                                  "<wp:Title>My App Title</wp:Title>" + 
                                                  "<wp:BackTitle>Back Tile Title</wp:BackTitle>" + 
                                                  "<wp:BackContent>Some additional content to be displayed</wp:BackContent>" + 
                                                  "<wp:BackBackgroundImage>BackOfTileImage.png</wp:BackBackgroundImage>" +
                                              "</wp:Tile> " +
                                         "</wp:Notification>";

The new elements are:

BackTitle – The title to be displayed on the back of the tile

BackContent – The additional content to be displayed on back of the tile

BackBackgroundImage – The image 173x173 to use on the back of the tile. Can be local (as in this example) or from a remote server, assuming you specify a url that is on one of the permitted domains (see setup of push notifications)

Id – The Id attribute of the Tile element is used to identify tiles in the case where there are multiple tiles pinned to the Start for a given app. The default tile (which is created when the user pins the app from the apps list, as per current version of wp7) has an Id of “” or you can omit this attribute. The Id of a tile also determines the page, and corresponding query string, to be navigated to when the user clicks on the tile.

Raw Notifications

I’m not aware of any changes to raw notifications themselves. However, the service that is used to send notifications can register for a callback when the device becomes inactive – particularly if you are sending large numbers of raw messages out to a phone. More information is available via MSDN on Setting up a Callback Registration Request

Comments are closed