Advertisment

Win Phone 7: Notification Services

author-image
PCQ Bureau
New Update

One of the biggest things that are reportedly “missing” from the Windows Phone 7 device is the lack of multi-tasking. However, Microsoft has an answer to this. WP7 does not enable multitasking for 3rd party applications for a number of reasons. First off, running a single application at a time allows the app to use the full resources of the phone — unlike when multiple applications are running. You must remember that a phone is not a desktop where multiple applications can run coolly with each other. The second reason is that a single application running drains the battery much less. And finally, some of the stuff that can be done through a multitasking set of applications can be done by using the Notification Services API available for the phone and through a set of MS services in the cloud.

Advertisment

Notification Services

There are three things that can be done with the API in Windows Phone:

Advertisment

1. Send a notification directly to a running application from a custom application service you have written. This will go through the MS notification service to the phone. This is called a “Raw” notification.

2. Send a “Toast” notification to the phone. This pops out of the top of the phone like a SMS and stays visible for 10 seconds, even when the app is not running. Clicking the toast will immediately launch the application to which the toast was sent.

3. Change the “Live Tile” of an app that's pinned to the Start screen. This allows you to create tiles that update automatically and can show a bunch of different information.

Advertisment

To get any of the different types of notifications, there is a process that needs to be followed.

Step 1: The application on the phone registers a “Channel” with the MS notification service.

Step 2: The Notification Service (hosted on Windows Azure) sends back a unique URI for that channel which identifies the phone.

Step 3: The application binds the type of notification(s) it can/wishes to receive to this URI

Step 4: A custom service that you build can then call the service using the same channel and URI information

Step 5: The MS service will send the correct notification to the URI formatted according to the way it is expected.

Step 6: A Push Notification client on the phone gets the notification and creates the toast, tile or sends it to the app if running directly.

Advertisment

The raw notification can be sent in any XML formatted manner with your own custom data. However in the case of the other notifications, you need to format the data in exactly the following manner.

The “Toast” accepts two parameters — the title and the ­sub-title. The XML is formatted in the following manner:

Advertisment

string ToastPushXML = "X-WindowsPhone-Target:

toast\r\n\r\n" +

"" +

" xmlns:wp='WindowsPhonePushNotification'>" + "" +

"Title" +

"Sub-title" +

"
" +

"";

The Tile notification takes 3 parameters — the tile's background image, a integer counter to show on the tile and a message text. The XML looks like this:

Advertisment

string tileMessage = "X-WindowsPhone-Target: tile\r\n\r\n" +

"" +

Advertisment

"" +

"" +

/Images/NewTile.png" +

"5" +

"Unread Mail" +

" " +

"";

Although the code required to setup the notification is too long to show in the article, there are a bunch of helper methods and utility classes available that make it simpler and shorter to write — and also which you can reuse in different apps. “Live Tiles” are a unique method of updating information for the user and makes your app stand out from the rest.

This concludes the Windows Phone 7 development series. However there are many other things that you can do with the API as well which we have not covered — using maps, location services, the camera, sensors, the marketplace, trial software versions, and more. Windows Phone 7 devices are now available in India and it is high time that you start developing apps for it too. Happy coding!

Advertisment