Get IMEI IMSI 3rd

來源:互聯網
上載者:User

Retrieving IMEI, IMSI, Network Info (Cell Id, Location Code) 3rd Edition.

In the 2nd edition there are many ways to retrieve the IMEI and IMSI. The one popularly used is the 3rd party “MobInfo Dll”. In Series 60 3rd edition there is no such third party Dll. Instead “CTelephony” needs to be used.

I’ve seen lots of threads for 2nd edition, but did not get good pointers for retrieving these parameters for 3rd edition.

Following is my contribution on how to retrieve IMEI and IMSI. Along with that you can also use this code to retrieve network info (Cell Id, Location code) It can further be extended to retrieve other network info.

Header File<br />#ifndef __SYSTEM_MANAGER_H__<br />#define __SYSTEM_MANAGER_H__</p><p>#include <Etel3rdParty.h></p><p>class CystemManager : public CActive<br />{<br />public:<br /> typedef enum {EHandsetIMEI, EHandsetIMSI, EHandsetNetworkInfo } InfoType;</p><p>public:<br /> static CystemManager* NewL();</p><p> // Destructor<br /> ~CSystemManager();</p><p>public:<br />// New functions<br /> void StartL(); // Request</p><p> const TPtrC GetIMEI();<br /> const TPtrC GetIMSI();<br /> void GetNetworkInfoL(TUint& aLocation, TUint& aCellId);</p><p>private:<br /> // C++ constructor<br /> CSystemManager();<br /> // Second-phase constructor<br /> void ConstructL();</p><p> // From CActive<br /> void RunL();</p><p> // Cancel<br /> void DoCancel();</p><p>private:<br /> enum TGetInfoState<br /> {<br /> EStart = 1,<br /> EGetPhoneInfo,<br /> EDone<br /> };</p><p>private:<br /> InfoType iPhoneInfoType;<br /> TInt iState; // State of the active object<br /> CTelephony* iTelephony;</p><p> CTelephony::TPhoneIdV1 iPhoneId;<br /> CTelephony::TSubscriberIdV1 iSubscriberId;<br /> CTelephony::TNetworkInfoV1 iNetworkInfo;</p><p> CActiveSchedulerWait iActiveSchedulerWait;<br /> TBuf<CTelephony::KPhoneSerialNumberSize>iIMEI;<br /> TBuf<CTelephony::KIMSISize> iIMSI;<br /> TUint iCellId;<br /> TUint iLocationAreaCode;<br />};<br />#endif // __SYSTEM_MANAGER_H__</p><p>Source File</p><p>// System includes<br />#include <badesca.h><br />#include <e32std.h><br />#include <eikenv.h><br />#include <eikappui.h><br />#include <eikapp.h><br />#include <etelbgsm.h></p><p>//User includes<br />#include "SystemManager.h"</p><p>CSystemManager* CSystemManager::NewL()<br />{<br /> CSystemManager* self = new (ELeave) CSystemManager();<br /> CleanupStack::PushL(self);<br /> self->ConstructL();<br /> CleanupStack::Pop(self);</p><p> return self;<br />}</p><p>CSystemManager::CSystemManager() : CActive(EPriorityHigh), // HIGH priority<br /> iPhoneInfoType(EHandsetIMEI),<br /> iState(EStart),<br /> iTelephony(NULL),<br /> iIMEI(0),<br /> iIMSI(0),<br /> iCellId(0),<br /> iLocationAreaCode(0)<br />{</p><p>}</p><p>void CSystemManager::ConstructL()<br />{<br /> iTelephony = CTelephony::NewL();<br /> CActiveScheduler::Add(this); // Add to scheduler<br />}</p><p>CSystemManager::~CSystemManager()<br />{<br /> Cancel(); // Cancel any request, if outstanding<br /> // Delete instance variables if any<br /> delete iTelephony;<br />}</p><p>void CSystemManager::DoCancel()<br />{<br /> switch(iPhoneInfoType)<br /> {<br /> case EHandsetIMEI:<br /> iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);<br /> break;<br /> case EHandsetIMSI:<br /> iTelephony->CancelAsync(CTelephony::EGetSubscriberIdCancel);<br /> break;<br /> default:<br /> iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);<br /> break;<br /> }<br />}</p><p>void CSystemManager::StartL()<br />{<br /> Cancel(); // Cancel any request, just to be sure<br /> iState = EGetPhoneInfo;<br /> switch(iPhoneInfoType)<br /> {<br /> case EHandsetIMEI:<br /> {<br /> CTelephony::TPhoneIdV1Pckg phoneIdPckg( iPhoneId );<br /> iTelephony->GetPhoneId(iStatus, phoneIdPckg);<br /> }<br /> break;<br /> case EHandsetIMSI:<br /> {<br /> CTelephony::TSubscriberIdV1Pckg subscriberIdPckg( iSubscriberId );<br /> iTelephony->GetSubscriberId(iStatus, subscriberIdPckg);<br /> }<br /> break;<br /> case EHandsetNetworkInfo:<br /> {<br /> CTelephony::TNetworkInfoV1Pckg networkInfoPckg( iNetworkInfo );<br /> iTelephony->GetCurrentNetworkInfo(iStatus, networkInfoPckg);<br /> }<br /> break;<br /> }</p><p> SetActive(); // Tell scheduler a request is active<br /> iActiveSchedulerWait.Start();<br />}</p><p>void CSystemManager::RunL()<br />{<br /> iState = EDone;<br /> if ( iActiveSchedulerWait.IsStarted() )<br /> {<br /> iActiveSchedulerWait.AsyncStop();<br /> if(iStatus == KErrNone)<br /> {<br /> switch(iPhoneInfoType)<br /> {<br /> case EHandsetIMEI:<br /> iIMEI.Append(iPhoneId.iSerialNumber );<br /> break;<br /> case EHandsetIMSI:<br /> iIMSI.Append(iSubscriberId.iSubscriberId );<br /> break;<br /> case EHandsetNetworkInfo:<br /> iCellId = iNetworkInfo.iCellId;<br /> iLocationAreaCode = iNetworkInfo.iLocationAreaCode;<br /> break;<br /> }<br /> }<br /> else<br /> {<br /> // ***********Handle Error here ************<br /> }<br /> }<br />}</p><p>const TPtrC CSystemManager::GetIMEI()<br />{<br /> iPhoneInfoType = EHandsetIMEI;<br /> iIMEI.Zero();</p><p> StartL();<br /> TPtrC ptr(iIMEI.Ptr());<br /> return ptr;<br />}</p><p>const TPtrC CSystemManager::GetIMSI()<br />{<br /> iPhoneInfoType = EHandsetIMSI;<br /> iIMSI.Zero();</p><p> StartL();<br /> TPtrC ptr(iIMSI.Ptr());<br /> return ptr;<br />}</p><p>void CSystemManager::GetNetworkInfoL(TUint& aLocationCode, TUint& aCellId)<br />{<br /> iPhoneInfoType = EHandsetNetworkInfo;<br /> StartL();<br /> aCellId = iCellId;<br /> aLocationCode = iLocationAreaCode;</p><p> return;</p><p>}<br />

 

Note: This piece of code requires "ReadDeviceData" Capability.

You can further extend the above code for retrieving other network information.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.