In this article we will see how to create an Alarm and a Reminder in Windows Phone.
Creating Alarm
- Alarm can be created using the Alarm class.
- Alarm class is part of Microsoft.Phone.Scheduler namespace.
- Alarm class takes the name of the alarm as the input parameter of the constructor.
- The name of the alarm must be unique within the application.
- Other properties of the Alarm class are as below:
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.
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:
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
- Reminder can be created using Reminder class.
- Reminder class is part of Microsoft.Phone.Scheduler namespace
- It is inherited from ScehduleNotification class.
- Name of the Reminder must be unique in the application
- Title of the reminder can be set.
- Custom sound is not supported in reminder. All reminders play the same sound.
- A reminder can be navigated to a specific page on tapping by the user. This is not supported in Alarms.
- Other properties are as below:
Various properties of a Reminder are explained below:
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:
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.