现在的位置: 首页 > 综合 > 正文

symbian 来电铃声及情景模式设置-转

2012年12月12日 ⁄ 综合 ⁄ 共 5036字 ⁄ 字号 评论关闭
symbian 来电铃声及情景模式设置
2010年05月19日 星期三 08:31 P.M.

下面是自己编写symbian情景模式设置的一点心得,以代码提供.可运行在3rd上.

#include "RingManager.h"
CRingManager::CRingManager()
{
}

CRingManager::~CRingManager()
{
}
//=============================================================================
//设置闹钟
TBool CRingManager::SetClockRing(const TDesC& aPath)
{
TInt ret = KErrNone;
RFs aFs;
aFs.Connect();
if (!(BaflUtils::FileExists(aFs, aPath)))
{
ret = KErrNotFound;
}
aFs.Close();
if (ret == KErrNone)
{
const TUid KCRUidClockApp =
{
0x101F874D
};
const TUint32 KClockAppSoundFile = 0x00000000;
CRepository* iRepository = CRepository::NewL(KCRUidClockApp);
CleanupStack::PushL(iRepository);
ret = iRepository->Set(KClockAppSoundFile, aPath);
CleanupStack::PopAndDestroy();
}
if (ret == KErrNone)
{
return TRUE;
}
else
{
return FALSE;
}
}
//=============================================================================
//获取闹钟铃声
TFileName CRingManager::GetClockRing()
{
TFileName toneFile;
const TUid KCRUidClockApp =
{
0x101F874D
};
const TUint32 KClockAppSoundFile = 0x00000000;
CRepository* iRepository = CRepository::NewL(KCRUidClockApp);
CleanupStack::PushL(iRepository);
iRepository->Get(KClockAppSoundFile,toneFile);
CleanupStack::PopAndDestroy();
return toneFile;

}

//=============================================================================
//设置来电铃声
TBool CRingManager::SetCallRing(const TDesC& aPath)
{
TInt ret = KErrNone;
RFs aFs;
aFs.Connect();
if (!(BaflUtils::FileExists(aFs, aPath)))
{
ret = KErrNotFound;
}
aFs.Close();
if (ret == KErrNone)
{

const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7E000001, mode);
TInt k = mode << 24 | 0x04; //来电铃声
ret=repository->Set(k, aPath);

repository->Set(0x7E000008,1); //铃声声量

delete repository;
repository = NULL;
//重起情景模式。
MProfileEngine* profileEngine = CreateProfileEngineL();
CleanupReleasePushL(*profileEngine);
profileEngine->SetActiveProfileL(profileEngine->ActiveProfileId());
CleanupStack::PopAndDestroy(1);

}

if(ret == KErrNone)
{
return TRUE;
}
else
{
return FALSE;
}

}
//=============================================================================
//获取来电钤声
TFileName CRingManager::GetCallRing()
{
TFileName toneFile;
const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7e000001, mode);
TInt k = mode << 24 | 0x04; //来电铃声
repository->Get(k,toneFile);

delete repository;
repository = NULL;
return toneFile;
}

//=============================================================================
//设置信息提示声 信息铃声设置不需要重启情景模式
TBool CRingManager::SetMsgRing(const TDesC& aPath)
{
TInt ret = KErrNone;
RFs aFs;
aFs.Connect();
if (!(BaflUtils::FileExists(aFs, aPath)))
{
ret = KErrNotFound;
}
aFs.Close();
if (ret == KErrNone)
{
const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7e000001, mode);
TInt k = mode << 24 | 0x06; //信息提示声
ret=repository->Set(k, aPath);
delete repository;
repository = NULL;
}
if (ret == KErrNone)
{
return TRUE;
}
else
{
return FALSE;
}
}

//=============================================================================
//获取信息提示声
TFileName CRingManager::GetMsgRing()
{
TFileName toneFile;
const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7e000001, mode);
TInt k = mode << 24 | 0x06; //信息提示声
repository->Get(k,toneFile);
delete repository;
repository = NULL;
return toneFile;
}

//=============================================================================
//设置振动开关
TBool CRingManager::SetLibrateRing(TBool bOpen)
{
//设置当前情景模式与铃声
const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7e000001, mode);

TInt k = mode << 24 | 0x0a;
TInt ret = KErrNone;
ret = repository->Set(k, bOpen);
delete repository;
repository = NULL;

//重起情景模式。
MProfileEngine* profileEngine = CreateProfileEngineL();
CleanupReleasePushL(*profileEngine);
profileEngine->SetActiveProfileL(profileEngine->ActiveProfileId());
CleanupStack::PopAndDestroy(1);
if (ret == KErrNone)
{
return TRUE;
}
else
{
return FALSE;
}

}

TBool CRingManager::GetLibrateRing()
{
const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7e000001, mode);

TInt k = mode << 24 | 0x0a;
TBool bLibrate=false;
repository->Get(k,bLibrate);
delete repository;
repository = NULL;
return bLibrate;
}

//=============================================================================
//设置音量大小( aVolume(0,10))
TBool CRingManager::SetRingVolume(TInt aVolume)
{
if (aVolume < 1)
aVolume = 1;

if (aVolume > 10)
aVolume = 10;

const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1,ret;
repository->Get(0x7e000001, mode);

for(int i=0;i<100;i++)
{
TInt k = mode << 24 | i;

ret=repository->Set(k, 1);
}
delete repository;
repository = NULL;

//重起情景模式。
MProfileEngine* profileEngine = CreateProfileEngineL();
CleanupReleasePushL(*profileEngine);
profileEngine->SetActiveProfileL(profileEngine->ActiveProfileId());
CleanupStack::PopAndDestroy(1);
if (ret == KErrNone)
{
return TRUE;
}
else
{
return FALSE;
}
}
TInt CRingManager::GetRingVolume()
{
TInt aVolume;
const TUid KUidSound =
{
0x101f8798
};
CRepository* repository = CRepository::NewL(KUidSound);
TInt mode = -1;
repository->Get(0x7e000001, mode);
TInt ret = KErrNone;
repository->Get(0x7E000008,aVolume); //铃声声量
delete repository;
repository = NULL;
return aVolume;
}

抱歉!评论已关闭.