米度软件:www.midosoft.cn
CImeiReader example illustrates how to read IMEI (which is an identification number that is unique for each mobile phone) in 3rd Edition Symbian devices. When this code is run on emulator it gives IMEI as "0000000000000", so better to test it on real device.
Library Needed:
LIBRARY etel3rdParty.lib
IMEI_Getter.cpp
#include "IMEI_Getter.h"
CImeiReader* CImeiReader::NewL(MImeiObserver* aObserver)
{
CImeiReader* self = NewLC(aObserver);
CleanupStack::Pop(self);
return self;
}
CImeiReader* CImeiReader::NewLC(MImeiObserver* aObserver)
{
CImeiReader* self = new (ELeave) CImeiReader(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CImeiReader::CImeiReader(MImeiObserver* aObserver)
:CActive(EPriorityStandard), iObserver(aObserver), iIdV1Pkg(iIdV1)
{
}
CImeiReader::~CImeiReader()
{
Cancel();
delete iTelephony;
}
void CImeiReader::ConstructL(void)
{
CActiveScheduler::Add(this);
iTelephony = CTelephony::NewL();
iTelephony->GetPhoneId(iStatus,iIdV1Pkg);
SetActive();
}
void CImeiReader::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
}
void CImeiReader::RunL()
{
iObserver->GotIMEIL(iIdV1.iSerialNumber,iStatus.Int());
}
IMEI_Getter.h
#include <Etel3rdParty.h>
class MImeiObserver
{
public:
virtual void GotIMEIL(const TDesC& aIMEI,TInt aError) = 0;
};
class CImeiReader : public CActive
{
public:
static CImeiReader* NewL(MImeiObserver* aObserver);
static CImeiReader* NewLC(MImeiObserver* aObserver);
~CImeiReader();
protected:
void DoCancel();
void RunL();
private:
CImeiReader(MImeiObserver* aObserver);
void ConstructL(void);
private:
MImeiObserver* iObserver;
CTelephony* iTelephony;
CTelephony::TPhoneIdV1 iIdV1;
CTelephony::TPhoneIdV1Pckg iIdV1Pkg;
};
米度软件:www.midosoft.cn