×
Namespaces

Variants
Actions
Revision as of 12:27, 24 June 2011 by hamishwillee (Talk | contribs)

Alarm clock with custom sound

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5235 ,X6, N97, N8
Compatibility
Platform(s): S60/Symbian
S60 5th Edition
Article
Keywords: Alarm
Created: somnathbanik ()
Last edited: hamishwillee (24 Jun 2011)


Contents

Introduction

This article shows you how to set your own song to clock alarm and play when the alarm expires. Most of the code are common and are taken from the Wiki, but the extra thing that is being added is setting own audio file to the alarm server. This code has been tested on 5th edition and S^3 devices, but also expected to work on 3rd edition too.


MMP

LIBRARY        centralrepository.lib alarmclient.lib alarmshared.lib apgrfx.lib
CAPABILITY WriteDeviceData

Header Files

If the header files are not in the SDK , then get it from API Plug-in

#include <clockdomaincrkeys.h>
#include <centralrepository.h> // Headers Used for CRepository
#include <ASShdDefs.h>
#include <calendarinternalcrkeys.h>
//check clock alarm
#include <almconst.h>
#include <ASCliSession.h> // For RASCliSession.
#include <ASShdAlarm.h> // For TASShdAlarm.
// System Includes
#include <apgcli.h> // for RApaLsSession
#include <apacmdln.h> // for CApaCommandLine
class CRepository;
class RASCliSession;
 
const TInt KWakeupAlarmFlagIndex = 0; // wakeup alarm
CRepository* iRepository;// = CRepository::NewL( KCRUidClockApp );
TInt iErrCode;
TInt iVal;
TBuf<200> iDispVal;
RASCliSession iCliSession;
TASShdAlarm alarm;

ConstructL()

          iCliSession.Connect();
iRepository = CRepository::NewL( KCRUidClockApp );// alarm clock

Destructor

if(iRepository)
{
delete iRepository;
iRepository =NULL;
 
}
 
iCliSession.Close();


Check Alarm Type

check the alarm type with the UID because it could be a clock or a calendar alarm

RArray<TAlarmId> ids;
// Get List of all alarm
iCliSession.GetAlarmIdListL(ids);
TASShdAlarm alarm;
for (TInt i = 0; i < ids.Count(); i++)
{
TInt err(KErrNone);
err = iCliSession.GetAlarmDetails(ids[i], alarm);
if ((!err))
{
if (alarm.Category().iUid == KAlarmClockOne.iUid)
{
CEikonEnv::InfoWinL(_L("Clock Alarm"), alarm.Message());
}
else
{
CEikonEnv::InfoWinL(_L("Not Clock Alarm"), alarm.Message());
}
}
}

Check Active Song of the Alarm

you can check the song that is being set in the alarm server

iErrCode = iRepository->Get(KClockAppSoundFile, iDispVal);
if (iErrCode == KErrNone)
{
iEikonEnv->AlertWin(_L("Song: "), iDispVal);
}
else
{
iDispVal.Num(iErrCode);
iEikonEnv->AlertWin(_L("error"), iDispVal);
}

Set Own song to Alarm

This code helps you to add your own audio file to the alarm server.

_LIT(KSampleAudio,"C:\\system\\E829D5AB\\sample.wav");
iErrCode = iRepository->Get(KClockAppSoundFile, iDispVal);
if (iErrCode == KErrNone)
{
iRepository->Set(KClockAppSoundFile, KSampleAudio);
}
else
{
iDispVal.Num(iErrCode);
iEikonEnv->AlertWin(_L("error"), iDispVal);
}

Add Aalrm to the Alarm Server

Now add alarm to the alarm server and this is a wakeup alarm.

TAlarmCategory alarmCategory = KAlarmClockOne;//KASCliCategoryClock;
alarm.Category()=alarmCategory;
_LIT(KAlarmMessage, "RingingAlarm");
alarm.Message() = KAlarmMessage;
 
alarm.RepeatDefinition() = EAlarmRepeatDefintionRepeatDaily; // alarm daily
alarm.ClientFlags().Set(KWakeupAlarmFlagIndex);// wake up alarm
alarm.NextDueTime().HomeTime();
//EAlarmRepeatDefintionRepeatDailyOnGivenDays
alarm.NextDueTime() += TTimeIntervalMinutes(1);//Seconds(61);
iCliSession.AlarmAdd(alarm);

Update alarm time

We have updated the alarm time but need to find Alarm Message in the alarm server. This is to be done so that we don't delete any other alarm of same or different type from the server.

RArray<TAlarmId> ids;
// Get List of all alarm
iCliSession.GetAlarmIdListL(ids);
TASShdAlarm alarm;
for (TInt i = 0; i < ids.Count(); i++)
{
TInt err(KErrNone);
err = iCliSession.GetAlarmDetails(ids[i], alarm);
if ((!err))
{
if (alarm.Category().iUid == KAlarmClockOne.iUid)
{
iCliSession.AlarmDeleteByCategory(alarm.Category(),EAllAlarms);
//CEikonEnv::InfoWinL(_L("Clock Alarm"), alarm.Message());
if(alarm.Message().Compare(_L("RingingAlarm"))==0)
{
 
//iCliSession.AlarmDeleteByCategory(alarm.Category(),EAllAlarms);
iCliSession.AlarmDelete(alarm.Id()); // delete clock alarm by its ID
CEikonEnv::InfoWinL(_L("Clock Alarm"),_L("Set"));
}
}
else
{
 
//CEikonEnv::InfoWinL(_L("Not Clock Alarm"), alarm.Message());
//iCliSession.AlarmDeleteByCategory(alarm.Category(),EAllAlarms); //delete other alarm
}
}
}

--somnathbanik 06:21, 28 December 2010 (UTC)By Somnath Banik

104 page views in the last 30 days.
×