Creating an Alarm And a Reminder in Windows Phone

In this article we will see how to create an Alarm and a Reminder in Windows Phone.

Creating Alarm

  1. Alarm can be created using the Alarm class.
  2. Alarm class is part of Microsoft.Phone.Scheduler namespace.
  3. Alarm class takes the name of the alarm as the input parameter of the constructor.
  4. The name of the alarm must be unique within the application.
  5. Other properties of the Alarm class are as below:

AlrmRmWPhn1.jpg

You can find explanations of properties as below. The Alarm class is inherited from the ScheduleNotification class. Some of the properties are inherited from the base class.

AlrmRmWPhn2.jpg

An Alarm can be created as below:

var newAlaram = new Alarm("myalarm")
                            {
                                Content="Hey Office Time",
                                BeginTime= DateTime.Now.AddMinutes(2),
                                RecurrenceType = RecurrenceInterval.Daily,
                                ExpirationTime = DateTime.Today.AddDays(30),
                               // sound= new Uri("music1.wav",UriKind.Relative)
                            };
 
ScheduledActionService.Add(newAlaram);


In the code shown above, the last line adds the alarm to the phone. The ScheduledActionService class add method is used to add an alarm to the phone. On running you should be getting an alarm after 2 minutes as below:

AlrmRmWPhn3.jpg

The best practice is to give the name of the alarm as a GUID. Since the name of the alarm must be unique in the application and it is not visible to the user so it should be given the name as GUID.

Creating Reminder

  1. Reminder can be created using Reminder class.
  2. Reminder class is part of Microsoft.Phone.Scheduler namespace
  3. It is inherited from ScehduleNotification class.
  4. Name of the Reminder must be unique in the application
  5. Title of the reminder can be set.
  6. Custom sound is not supported in reminder. All reminders play the same sound.
  7. A reminder can be navigated to a specific page on tapping by the user. This is not supported in Alarms.
  8. Other properties are as below:

AlrmRmWPhn4.jpg

Various properties of a Reminder are explained below:

AlrmRmWPhn5.jpg

A Reminder can be created as below:

Reminder reminder = new Reminder("myreminder")
                              {
                                  Title = "Debugmode app reminder",
                                  Content = "Hey Go to party",
                                  BeginTime = DateTime.Now.AddMinutes(2),
                                  RecurrenceType = RecurrenceInterval.Daily,
                                  ExpirationTime = DateTime.Today.AddDays(30),
                                  NavigationUri = new Uri("Page1.xaml"UriKind.Relative)

                                  
                              };
             ScheduledActionService.Add(reminder);


In the above code, the last line adds the reminder to the phone. The ScheduledActionService class method is used to add reminders to the phone. On running you should be getting a reminder after 2 minutes as below:

AlrmRmWPhn6.jpg

On tapping, the user will be navigated to Page1.xaml.

This is how you can create and schedule an Alarm and a Reminder in Windows Phone. I hope this article is useful. Thanks for reading.
 

Up Next
    Ebook Download
    View all
    Learn
    View all