×
Namespaces

Variants
Actions

Reading IMEI in 3rd edition -Synchronously

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code Example
Source file: Media:ReadIMEI.zip
Article
Created: kiran10182 (27 Mar 2007)
Last edited: hamishwillee (26 Jul 2012)

IMEI stands for "International Mobile Equipment Identity". There is a frequent use of reading IMEI in mobile phone development. People generally use IMEI for license/full version support of an application.


IMEIApp.h

#include <e32base.h>
#include <Etel3rdParty.h>
 
class CIMEIApp : public CActive
{
private:
void ConstructL();
CTelephony* iTelephony;
CTelephony::TPhoneIdV1 iPhoneIdV1;
CTelephony::TPhoneIdV1Pckg iPhoneIdV1Pckg;
 
public:
CIMEIApp(TDes& aIMEI);
~CIMEIApp();
static void GetIMEI(TDes& aIMEI);
TDes& IMEI;
 
private:
/*
These are the pure virtual methods from CActive that
MUST be implemented by all active objects
*/

void RunL();
void DoCancel();
};

IMEIApp.cpp

#include "IMEIApp.h"
 
void CIMEIApp::GetIMEI(TDes& aIMEI)
{
CIMEIApp* self= new (ELeave) CIMEIApp(aIMEI);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::PopAndDestroy(self);
}
 
void CIMEIApp::ConstructL()
{
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this);
 
iTelephony->GetPhoneId(iStatus, iPhoneIdV1Pckg);
SetActive();
CActiveScheduler::Start();
}
 
CIMEIApp:: CIMEIApp(TDes& imei): CActive(EPriorityStandard),IMEI(imei),iPhoneIdV1Pckg(iPhoneIdV1)
{
//default constructor
}
 
CIMEIApp::~CIMEIApp()
{
delete iTelephony;
iTelephony = NULL;
}
 
void CIMEIApp::RunL()
{
if(iStatus==KErrNone)
{
IMEI= iPhoneIdV1.iSerialNumber;
CActiveScheduler::Stop();
}
}
 
void CIMEIApp::DoCancel()
{
iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
}

Now do the following steps:
1) Create a sample "Hello World" type application.
2) Put IMEIApp.h file in your application's inc folder.
3) Put IMEIApp.cpp file in your application's src folder.
4) Open .mmp file and add entry SOURCE IMEIApp.cpp.
5) Open .mmp file and add entry LIBRARY etel3rdparty.lib.
7) Now you need to include following header in your class to read IMEI:
#include "IMEIApp.h". Let's say in for e.g.: "CYrAppUi.h"
8) You can then call the static function from any of your Commands.
For ex: in your CYrAppUi.h you need to include "IMEIApp.h"
And Call it like:

case EReadIMEICommand1:
{
TBuf<25> iIMEI;
CIMEIApp::GetIMEI(iIMEI);
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
informationNote->ExecuteLD(iIMEI);
}

You can find a working application which can be built with Carbide.c++.
Here it goes: Read IMEI

See Also

[show details]
This page was last modified on 26 July 2012, at 09:12.
112 page views in the last 30 days.
×