Activating an Alarm on Given Days

This tutorial explains the steps required to activate an alarm that expires, or goes OFF on one or more days of the week.

Introduction

The TASShdAlarm class provides functions that enable an alarm to repeat on specified days of the week. This alarm is known as a Daily On Given Days alarm. The alarm can be repeated weekly on a single day or on multiple days. The alarms can also be repeated at the same time on every specified day.

If the user changes the system date or time, the alarm expires once. Unlike a Repeat Once alarm, a Daily On Given Days alarm is not deleted but rescheduled for the next available expiry time.

Procedure

Follow the steps given below to create a Daily On Given Days alarm that is active on Monday and Wednesday of every week:

  1. Create an alarm with the TASShdAlarm class.

  2. Use theSetAlarmDays() API to specify the required days. EAlarmDayMonday and EAlarmDayWednesday are the parameters to specify that the alarm must repeat on Monday and Wednesday as shown in the code fragment.

    NOTE: SetAlarmDays() must be specifically used for EAlarmRepeatDefinitionRepeatDailyOnGivenDays repeat definition only.

  3. Use RASCliSession to create a session with the Alarm Server.

  4. Add the alarm to the Alarm Server using the AlarmAdd() API.

The following code fragment illustrates how to activate an alarm on the given days:


#include <ASCliSession.h>    // For RASCliSession.
#include <ASShdAlarm.h>      // For TASShdAlarm.

…

// Create an alarm that is active on Monday and Wednesday.
TASShdAlarm alarm;
alarm.RepeatDefinition() = EAlarmRepeatDefinitionRepeatDailyOnGivenDays;
alarm.SetAlarmDays( EAlarmDayMonday | EAlarmDayWednesday );

// Connect to Alarm Server.
RASCliSession alarmSession;
User::LeaveIfError( alarmSession.Connect() );
CleanupClosePushL( alarmSession );

// Add the alarm to Alarm Server.
User::LeaveIfError( alarmSession.AlarmAdd( alarm ) );

CleanupStack::PopAndDestroy();

Results

The alarm is set to repeat every week on Monday and Wednesday.