How to retrieve the phone IMEI code Tuesday, August 4, 2009

Here I’ll present an approach to retrieve IMEI code by calling functions of class RMobilePhone. I have debugged these source codes on W950 (Symbian 9.1, UIQ3.0).
You can get some description of the format of IMEI code in [1]. In this paper, the PlpVariant::GetMachineIdL function is called to retrieve the phone IMEI code, but this function has been deprecated on UIQ3.0. So if you call it, you maybe will retrieve a incorrect IMEI code. I have debugged it on W950, the return is ‘14750005-630771776’. My phone IMEI code is actually ‘00440107-000879-8’.
And the link [2] provides another approach, but it’s so hard to get the mentioned .h files and librarys. I can not find them, so I did not debug it.
On UIQ 3.0, class RMobilePhone provides client access to mobile phone functionality provided by TSY. You can get the detailed description of class RMobilePhone in the help document of UIQ SDK.
My steps are as following:
1. Connect to the ETel server
2. Get the name of registered phones
3. Open mobile phone sub session
4. Check if the phone provided the capabilities to retrieve IMEI code or not
5. Retrieve the phone IMEI code

The defined parameters:


RTelServer iTelServer; // Root telephony server session
RMobilePhone iMmPhone;
TBuf<> iPhoneName
RMobilePhone::TMobilePhoneIdentityV1 iPhoneId;


1. Connect to the ETel server


User::LeaveIfError(iTelServer.Connect());


2. Get the name of registered phones


// Get the number of registered phones
TInt numberOfPhones;
User::LeaveIfError(aTelServer.EnumeratePhones(numberOfPhones));
LOG("%i",numberOfPhones);
for( TInt i = 0; i<numberOfPhones; i++ )
{
RTelServer::TPhoneInfo info;
iTelServer.GetPhoneInfo(i,info);
LOG("NetworkTyp:[%i],Name:[%S],NumberofLines:[%i],Extensions:[%i]", (TInt)info.iNetworkType,&info.iName,info.iNumberOfLines,info.iExtensions);
iPhoneName.Copy(info.iName);
}


In your smart phone, there can be several registered phones i.e. the returned value of ‘number ofPhones’ can be more than 1. hence you need to choice one directly or adopt other policy.But fortunately most of the smart phones have just one
3. Open mobile phone sub session


// open mobile phone sub session
User::LeaveIfError(iMmPhone.Open(iTelServer, iPhoneName));


4. Check if the phone provided the capabilities to retrieve IMEI code or not
And call the RMobilePhone::GetPhoneId function to retrieve IMEI.


TUint32 lCaps = 0;
TInt err = iMmPhone.GetIdentityCaps(lCaps);
if(err != KErrNone && err != KErrNotSupported)
{
LOG(_L("an unexpected error occoured"));
}
else if(err == KErrNotSupported)
{
LOG(_L("RMobilePhone::GetIdentityCaps() returned KErrNotSupported "));
}
else if (lCaps & RMobilePhone::KCapsGetSerialNumber)
{
iMmPhone.GetPhoneId(iStatus, iPhoneId); // asynchronous call
iActiveStatus = ST_GET_PHONE_ID;
SetActive();
return;
}


The function,RMobilePhone:: GetPhoneId, is the key function. In fact, here I introduce how to use it.
5. After returning, the value of the parameter, iPhoneId.iSerialNumber, is the phone IMEI code
6. Don't forget to close the opened handles as like:


iMmPhone.Close();
iTelServer.Close();



Reference:
1. “Retrieving the device IMEI code”
http://www.newlc.com/Retrieving-the-device-IMEI-code.html
2. “FAQ & Tech Tips”
http://www2.symbian.com/faq.nsf/7b5405edb1250e7c802569ee005d054e/ba491eaeb25c5c7d80256bf3003e75fc?OpenDocument

0 comments: