Creating Alarms and Reminders for Windows Phone

Introduction

With Windows Phone Mango, Microsoft introduced over 500 new features, big and small. One of the features it introduced was programmatic access to the alarms and reminders feature on the Windows Phone platform.

Alarms and reminders are two types of scheduled notifications, both of which reside in the Microsoft.Phone.Scheduler namespace.

The difference between an alarm and a reminder is that a reminder includes all the features of the alarm but in addition, a user can specify a URI. When a reminder pops up, a user can click it resulting in launching of the application and the URI is passed to it.

Hands On

To see the behavior of alarms and reminders ourselves, let's create a demo application. Create a new Silverlight for Windows phone application called WPAlarmDemo.

Now, add 4 buttons called "Add Alarm", "Delete Alarm", "Add reminder" and "Delete Reminder".

Your UI at this point should look like this:

My Application UI
Figure 1: "My Application" UI

For simplicity's sake, we will set our alarm and reminder to 10 seconds from the current system time. This will help speed up our testing.

On the code behind for MainPage.xaml page (MainPage.xaml.cs), add two variables of type Alarm and Reminder called "alarm" and "reminder".

public partial class MainPage : PhoneApplicationPage
    {
        Alarm alarm;
        Reminder reminder;
        // Constructor
        public MainPage()

Double click the "Add Alarm" button and enter the following code

private void buttonAddAlarm_Click(object sender, RoutedEventArgs e)
        {
            alarm = new Alarm("MyAlarm");
            alarm.BeginTime = DateTime.Now.AddSeconds(10);
            alarm.Content = "Alarm has fired";
            ScheduledActionService.Add(alarm);
        }

Now Add code to remove the alarm from the ScheduledAction list.

private void buttonDeleteAlarm_Click(object sender, RoutedEventArgs e)
        {
            ScheduledActionService.Remove("MyAlarm");
        }

Now, add similar code for the event handler for the click event on "Add Reminder" button.

private void buttonAddReminder_Click(object sender, RoutedEventArgs e)
        {
            reminder = new Reminder("MyReminder");
            reminder.BeginTime = DateTime.Now.AddSeconds(10);
            reminder.Content = "Reminder has fired";
            reminder.Title = "Reminder Demo";
            ScheduledActionService.Add(reminder);
        }

Finally, add code to remove the reminder from the ScheduledAction list.

private void buttonDeleteReminder_Click(object sender, RoutedEventArgs e)
        {
            ScheduledActionService.Remove("MyReminder");
        }

You are now ready to test your sample. Compile and execute your sample. If you are having issues compiling the code, you can get the sample code for this exercise below.

When we execute the application, click on the "Add Alarm" button. Wait for 10 seconds; you will see an alarm notification on the application page.

Alarm notification
Figure 2: Alarm notification

We can dismiss the alarm by clicking the "dismiss" button.

Now, click the "Add Reminder" button. After 10 seconds, we see a reminder show up.

Reminder Demo
Figure 3: Reminder Demo

In this demo application, I have not specified an URI but you might want to consider using that to get the full leverage from the reminder feature.

Summary

In this article, we learned how to create alarms and reminders in a Windows Phone application.



About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com

Related Articles

Downloads

Comments

  • ENipIC tW XU hpH HaIz HC

    Posted by egWFfjgniV on 06/24/2013 04:09pm

    Continue Reading viagra online price comparison - can you buy generic viagra from a store

    Reply
  • Mr

    Posted by Robert Tate on 06/30/2012 01:26am

    Hi, My wife and I are both on medication which has to be taken every other day. My question is can I set 2 alarms on my Nokia 800 so I am reminded whose turn it is to take their pill. Robert

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds