How to create alarm

来源:互联网 发布:互相依靠知乎 编辑:程序博客网 时间:2024/05/21 21:49


Reviewer Approved    
The following code snippet explains how to set an alarm in S60. This alarm is different from from the clock application's alarm and picks the same tone set for the calendar application's alarm. If vibration alert is on for the currently set profile, then vibrating alert will also be played when the alarm expires.
SDK Used : S60 3rd edition
#include <ASCliSession.h>
#include <ASShdAlarm.h>
#include <ASShdDefs.h>
 
Link Against : alarmclient.lib
Link Against : alarmshared.lib
RASCliSession iSession;  // client interface to alarm server
iSession.Connect();
TASShdAlarm iAlarm; //Alarm object
 
TTime ihomeTime;
ihomeTime.HomeTime(); // Get Current Hometime(local time set in mobile)
 
Tint  interval;
// interval – Give seconds after which alarm should expire
TTimeIntervalSeconds intervalSecs(interval);
 
//Returns the time alarm is scheduled to expire
TTime& iNDT = iAlarm.NextDueTime();
 
//Set the NextDueTime in which alarm will expire
iNDT = ihomeTime + intervalSecs;
 
TAlarmMessage& imessage(iAlarm.Message());
imessage.Copy(_L("Alarm")); //Alarm message
 
iSession.AlarmAdd(iAlarm);
iSession.Close();


Description
S60 devices that are switched off can switch on automatically to react to alarm events.
In the alarm startup mode, the user will see and hear the alarm and can choose whether the phone will be switched on.
The alarm server (RASCliSession) can be used to set an alarm to wake up the phone in the alarm startup mode.
Solution
Alarms can be set programmatically to turn on the device (in alarm startup mode) at a specified time. Note however, that there are no APIs available to initiate a normal power-up cycle directly - when using alarms, user interaction is required to switch on the device in alarm startup mode.
A specific flag must be set for the alarm (TASShdAlarm) to indicate that it is a wakeup alarm and should wake the device up even when powered off.
const TInt KWakeupAlarmFlagIndex = 0;
 
 TASShdAlarm alarm;
 alarm.ClientFlags().Set( KWakeupAlarmFlagIndex );