首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian英文资料 >> Network >> 正文
Retrieving IMEI, IMSI, Network Info (Cell Id, Location Code) on 3rd Edition.
作者:佚名    文章来源:newlc    更新时间:2007-1-5 14:59:53

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

#ifndef __SYSTEM_MANAGER_H__
#define __SYSTEM_MANAGER_H__

#include <Etel3rdParty.h>

class CystemManager : public CActive
{
public:
        typedef enum {EHandsetIMEI, EHandsetIMSI, EHandsetNetworkInfo } InfoType;
       
public:
        static CystemManager* NewL();

        // Destructor
        ~CSystemManager();

public:
// New functions
        void StartL();  // Request

        const TPtrC GetIMEI();
        const TPtrC GetIMSI();
        void GetNetworkInfoL(TUint& aLocation, TUint& aCellId);

private:
        // C++ constructor
        CSystemManager();
        // Second-phase constructor
        void ConstructL();



        // From CActive
        void RunL();

        // Cancel
        void DoCancel();

private:
        enum TGetInfoState
        {
                EStart = 1,
                EGetPhoneInfo,
                EDone
        };

private:
        InfoType                                                                 iPhoneInfoType;
        TInt                                                                         iState; // State of the active object
        CTelephony*                                                         iTelephony;
       
        CTelephony::TPhoneIdV1                                        iPhoneId;
        CTelephony::TSubscriberIdV1                         iSubscriberId;
        CTelephony::TNetworkInfoV1                                 iNetworkInfo;
       
        CActiveSchedulerWait                                         iActiveSchedulerWait;
        TBuf<CTelephony::KPhoneSerialNumberSize>iIMEI;
        TBuf<CTelephony::KIMSISize>                         iIMSI;
        TUint                                                                         iCellId;
        TUint                                                                         iLocationAreaCode;
};
#endif // __SYSTEM_MANAGER_H__

Source File


// System includes
#include <badesca.h>
#include <e32std.h>
#include <eikenv.h>
#include <eikappui.h>
#include <eikapp.h>
#include <etelbgsm.h>

//User includes
#include "SystemManager.h"

CSystemManager* CSystemManager::NewL()
{
        CSystemManager* self = new (ELeave) CSystemManager();
        CleanupStack::PushL(self);
        self->ConstructL();
        CleanupStack::Pop(self);

        return self;
}

CSystemManager::CSystemManager() : CActive(EPriorityHigh), // HIGH priority
                                                                iPhoneInfoType(EHandsetIMEI),
                                                                iState(EStart),
                                                                iTelephony(NULL),
                                                                iIMEI(0),
                                                                iIMSI(0),  
                                                                iCellId(0),
                                                                iLocationAreaCode(0)
{

}

void CSystemManager::ConstructL()
{
        iTelephony = CTelephony::NewL();
        CActiveScheduler::Add(this); // Add to scheduler
}

CSystemManager::~CSystemManager()
{
        Cancel(); // Cancel any request, if outstanding
        // Delete instance variables if any
        delete iTelephony;
}

void CSystemManager::DoCancel()
{
        switch(iPhoneInfoType)
        {
                case EHandsetIMEI:
                        iTelephony->CancelAsync(CTelephony::EGetPhoneIdCancel);
                        break;
                case EHandsetIMSI:
                        iTelephony->CancelAsync(CTelephony::EGetSubscriberIdCancel);
                        break;
                default:
                        iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);
                        break;
        }
}

void CSystemManager::StartL()
{
        Cancel(); // Cancel any request, just to be sure
        iState = EGetPhoneInfo;
        switch(iPhoneInfoType)
        {
                case EHandsetIMEI:
                        {
                                CTelephony::TPhoneIdV1Pckg phoneIdPckg( iPhoneId );
                                iTelephony->GetPhoneId(iStatus, phoneIdPckg);
                        }
                        break;
                case EHandsetIMSI:
                        {
                                CTelephony::TSubscriberIdV1Pckg subscriberIdPckg( iSubscriberId );
                                iTelephony->GetSubscriberId(iStatus, subscriberIdPckg);
                        }
                        break;
                case EHandsetNetworkInfo:
                        {
                                CTelephony::TNetworkInfoV1Pckg networkInfoPckg( iNetworkInfo );
                                iTelephony->GetCurrentNetworkInfo(iStatus, networkInfoPckg);
                        }
                        break;       
        }
       
        SetActive(); // Tell scheduler a request is active
        iActiveSchedulerWait.Start();
}

void CSystemManager::RunL()
{
        iState = EDone;
        if ( iActiveSchedulerWait.IsStarted() )
        {
                iActiveSchedulerWait.AsyncStop();
                if(iStatus == KErrNone)
                {
                        switch(iPhoneInfoType)
                        {
                                case EHandsetIMEI:
                                        iIMEI.Append(iPhoneId.iSerialNumber );
                                        break;
                                case EHandsetIMSI:
                                        iIMSI.Append(iSubscriberId.iSubscriberId );
                                        break;
                                case EHandsetNetworkInfo:
                                        iCellId = iNetworkInfo.iCellId;
                                        iLocationAreaCode = iNetworkInfo.iLocationAreaCode;
                                        break;
                        }
                }
                else
                {
               // ***********Handle Error here ************
                }
        }
}

const TPtrC CSystemManager::GetIMEI()
{
        iPhoneInfoType = EHandsetIMEI;
        iIMEI.Zero();

        StartL();
        TPtrC ptr(iIMEI.Ptr());
        return ptr;
}

const TPtrC CSystemManager::GetIMSI()
{
        iPhoneInfoType = EHandsetIMSI;
        iIMSI.Zero();

        StartL();
        TPtrC ptr(iIMSI.Ptr());
        return ptr;
}

void CSystemManager::GetNetworkInfoL(TUint& aLocationCode, TUint& aCellId)
{
        iPhoneInfoType = EHandsetNetworkInfo;
        StartL();
        aCellId = iCellId;
        aLocationCode = iLocationAreaCode;
       
        return;

}

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

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

相关文章:
How to retrieve the phone IMEI code on UIQ3.0
Tips & code samples for Sony Ericsson’s UIQ 3 based phones
Obtain IMEI number of your symbian phone from Your Go-DB application
Getting Started with Metrowerks Codewarrior
Common products UIDs
Obtain IMEI number of your symbian phone from Your Go-DB application
Obtain IMEI number of your symbian phone from Your Go-DB application
How to retrive the IMSI number
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号