[ZT]Symbian OS s60 3rd编程中实现IMSI、IMEI查询

#ifndef MYTELEPHONY_H
#define MYTELEPHONY_H

#include 
#include 

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

// 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());

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。