Setting contacts ringtone
设置联系人铃声
Reviewer Approved
Following function shows how to add a ringtone for a specific contact stored in contacts database.
aRingtone is the full name (with drive, path, name and extension) of the audio file to be set as a contacts ringtone
and aId is the contacts ID of the contact for which the ringtone is set to.
下面的函数展现了如何在联系人数据库,为指定联系人添加铃声。
aRingtone是要设置为联系人铃声的音频文件全名(包含驱动器、路径和扩展名)。
aId是要设置的联系人的ID。
Headers:
#include <cntdb.h>
#include <cntitem.h>
#include <cntfldst.h>
Link against:
LIBRARY cntmodel.lib
Capabilities:
CAPABILITY WriteDevicData
void AddRingtoneForContactL(const TDesC& aRingtone,TContactItemId aId)
{
CContactDatabase* ContactDb = CContactDatabase::OpenL();
CleanupStack::PushL(ContactDb);
CContactItem* SelItem = ContactDb->OpenContactL(aId);
CleanupStack::PushL(SelItem);
TInt RIndex = SelItem->CardFields().Find(KUidContactFieldRingTone);
if(RIndex != KErrNotFound)
SelItem->RemoveField(RIndex);
CContactItemField* contactField = CContactItemField::NewLC(KStorageTypeText,KUidContactFieldRingTone);
contactField->TextStorage()->SetTextL(aRingtone);
contactField->SetLabelL(_L("tone"));
contactField->SetMapping(KUidContactFieldVCardMapUnknown);
contactField->SetId(2);
SelItem->AddFieldL(*contactField);
CleanupStack::Pop();//ContactField
ContactDb->CommitContactL(*SelItem);
CleanupStack::PopAndDestroy(2);//ContactDb,SelItem
}