Windows Phone 8.1 For Developers–Notifications

This blog post is part of a series about how Windows Phone 8.1 affects developers. This blog post talks about how to Work with notifications and is written by Robert Hedgate (@roberthedgate) at Jayway and was originally posted here.


In this blog post I will do a quick overview of what is new with notifications in Windows Phone 8.1. This is the first impression of the functions so I do recommend you to take a look at MSDN if you want a deeper understanding of how it works.

Recap on how it is done in Windows Phone 8


Example of how to set up an alarm:

 var alarm = new Alarm("my alarm")
    Content = "my content",
    BeginTime = DateTime.Now.AddMinutes(1),
    ExpirationTime = DateTime.Now.AddHours(1),
    RecurrenceType = RecurrenceInterval.None




Example of how to set up a reminder:

 var reminder = new Reminder("my reminder")
    Title = "my title",
    Content = "my content",
    BeginTime = DateTime.Now.AddMinutes(1),
    ExpirationTime = DateTime.Now.AddHours(1),
    RecurrenceType = RecurrenceInterval.None,
    NavigationUri = null




Simple toast example:

 var toast = new ShellToast {Title = "My toast title", Content = "content"};


Windows Phone 8.1


In Windows Phone 8.1 we get the same toast system as Windows 8.1. It is a lot like how to tiles work, the toast are described with a XML-tree. Example of XML toast:

        <binding template="ToastText01">
            <text id="1">Line 1</text>

What different toast types there are can be found here, There are four with text and again the same four but also with an image. On the phone however the image is ignored if you use the type. So in principle there are only four types. There are a use case to set the image anyway and that is if you share code between a phone and store project. The different types can be found in the ToastTemplateType class, and retrieved with the GetTemplateContent function. The code becomes very similar to that of a tile update but instead of calling update we call show.

 var toastNotifier = ToastNotificationManager.CreateToastNotifier();
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
var toastText = toastXml.GetElementsByTagName("text");
(toastText[0] as XmlElement).InnerText = "Line 1";
var toast = new ToastNotification(toastXml);

To create a schedule toast it is very easy, just change it to a ScheduledToastNotification add a time and then add it to the schedule:

 var customAlarmScheduledToast = new ScheduledToastNotification(toastXml, DateTime.Now.AddSeconds(10));            


Alarm and Reminder

Alarm and reminder are not available in Windows Phone 8.1. There are no equivalent in Windows 8.1 for this. If this is a deal breaker for your app you can update to Silverlight 8.1 to still be able to use some of the other new features of Windows Phone 8.1.

If you choose Silverlight 8.1 both toast versions work side by side.