为了方便使用我将IMEI的查询也加入到原作者的的代码中,以方便我们的使用。以下代码来自于诺基亚论坛,代码原作者是chenziteng ,现转载其源代码于下(本人稍作修改):
头文件如下:
#ifndef MYTELEPHONY_H
#define MYTELEPHONY_H
#include <e32base.h>
#include <Etel3rdParty.h>
class CMyTelephony : public CActive
{
public:
static void GetIMSIL(TDes& aIMSI);
static void GetIMEIL(TDes& aIMEI);
static void GetPhoneType(TDes& aPhoneType);
static void DialPhone(const TDesC& aPhoneId);
static CMyTelephony* NewL();
protected:
void DoCancel();
void RunL();
private:
static CMyTelephony* NewLC();
~CMyTelephony();
CMyTelephony();
void ConstructL();
void GetSubscriberId();
void GetPhoneId();
private:
CTelephony* iTelephony;
CTelephony::TCancellationRequest iRequest;
CTelephony::TSubscriberIdV1 iSubscriberId;
CTelephony::TSubscriberIdV1Pckg iSubscriberIdPckg;
CTelephony::TPhoneIdV1 iPhoneId;
CTelephony::TPhoneIdV1Pckg iPhoneIdPckg;
CTelephony::TCallId iCallId;
TBuf<32> iPhoneType;
public :
void DialNewCall(const TDesC& aTelNumber);
};
#endif // MYTELEPHONY_H
cpp源文件如下:
// MyTelephony.cpp
//
#include <e32svr.h>
#include "MyTelephony.h"
#include <f32file.h>
class CTelephony;
CMyTelephony* CMyTelephony::NewLC()
{
CMyTelephony* self = new (ELeave) CMyTelephony;
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CMyTelephony* CMyTelephony::NewL()
{
CMyTelephony* self = CMyTelephony::NewLC();
CleanupStack::Pop(self);
return self;
}
void CMyTelephony::GetIMSIL(TDes& aIMSI)
{
#ifdef __WINS__
CMyTelephony* telephony = CMyTelephony::NewL();
telephony->GetSubscriberId();
aIMSI = telephony->iSubscriberId.iSubscriberId;
delete telephony;
#else
_LIT(KDebugIMSI, "000000000000000");
aIMSI = KDebugIMSI;
#endif
}
void CMyTelephony::GetIMEIL(TDes& aIMEI)
{
#ifndef __WINS__ //真实设备 This only works on target machine
CMyTelephony* telephony = CMyTelephony::NewL();
telephony->GetPhoneId();
aIMEI = telephony->iPhoneId.iSerialNumber;
delete telephony;
#else //模拟器 Return a fake IMEI when working onemulator
_LIT(KEmulatorImei, "000000000000000");
aIMEI=KEmulatorImei;
#endif
}
void CMyTelephony::GetPhoneType(TDes& aPhoneType)
{
#ifndef __WINS__
CMyTelephony* telephony = CMyTelephony::NewL();
telephony->GetPhoneId();
aPhoneType.Copy(telephony->iPhoneId.iManufacturer);
aPhoneType.Append(telephony->iPhoneId.iModel);
delete telephony;
#else //模拟器 Return a fake IMEI when working onemulator
_LIT(KPhoneType, "Nokia5500d");
aPhoneType=KPhoneType;
#endif
}
void CMyTelephony::DialPhone(const TDesC& aPhoneId)
{
#ifndef __WINS__ //真实设备 This only works on target machine
CMyTelephony* telephony = CMyTelephony::NewLC();
telephony->DialNewCall(aPhoneId);
#else //模拟器 Return a fake IMEI when working onemulator
#endif
}
void CMyTelephony::DoCancel()
{
iTelephony->CancelAsync(iRequest);
iTelephony->CancelAsync(CTelephony::EDialNewCallCancel);
}
void CMyTelephony::RunL()
{
CActiveScheduler::Stop();
}
CMyTelephony::~CMyTelephony()
{
delete iTelephony;
}
CMyTelephony::CMyTelephony() :
CActive(CActive::EPriorityStandard), iSubscriberIdPckg(iSubscriberId),
iPhoneIdPckg(iPhoneId)
{
CActiveScheduler::Add(this);
}
void CMyTelephony::ConstructL()
{
iTelephony = CTelephony::NewL();
}
void CMyTelephony::GetSubscriberId()
{
Cancel();
iRequest = CTelephony::EGetSubscriberIdCancel;
iTelephony->GetSubscriberId(iStatus, iSubscriberIdPckg);
SetActive();
CActiveScheduler::Start();
}
void CMyTelephony::GetPhoneId()
{
Cancel();
iRequest = CTelephony::EGetPhoneIdCancel;
iTelephony->GetPhoneId(iStatus, iPhoneIdPckg);
SetActive();
CActiveScheduler::Start();
}
/*
*此方法可以获得详细的手机型号,但是由于在此处使用时与活动对象易发生冲突,所以就没有采用等待后期修改
void CMyTelephony::GetType()
{
_LIT(KPath,"z:\\resource\\versions\\model.txt");
Cancel();
RFs fs;
RFile typeFile;
User::LeaveIfError(fs.Connect());
TFileText myFile;
User::LeaveIfError(typeFile.Open(fs, KPath, EFileShareReadersOnly));
// Read from position 0: start of file
myFile.Set(typeFile);
myFile.Read(iPhoneType); // readBuf1 is now "write "
fs.Close();
SetActive();
CActiveScheduler::Start();
}*/
/*
* 拨打电话
* */
void CMyTelephony::DialNewCall(const TDesC& aTelNumber)
{
CTelephony::TTelNumber telNumber(aTelNumber);
CTelephony::TCallParamsV1 callParams;
callParams.iIdRestrict = CTelephony::ESendMyId;
CTelephony::TCallParamsV1Pckg callParamsPckg(callParams);
iTelephony->DialNewCall(iStatus, callParamsPckg, telNumber, iCallId);
SetActive();
}
如何使用:
#include "MyTelephony.h"
...
TBuf<CTelephony::KIMSISize> imsi;
CMyTelephony::GetIMSIL(imsi); // synchronous
/*
TBuf<CTelephony::KIMEISize> imei;
CMyTelephony::GetIMEIL(iesi); // synchronous
*/
CEikonEnv::Static()->InfoWinL(imsi, KNullDesC());
...
向高手致敬!!
有关链接:
http://discussion.forum.nokia.com/forum/showthread.php?t=95966
修改后加入了查询手机型号、IMEI、IMSI、拨打电话号码等有关硬件信息,后期将进一步维护更新中。
转载自原文链接, 如需删除请联系管理员。
原文链接:Symbian OS s60 3rd编程中实现IMSI、IMEI查询,转载请注明来源!