区分当前用户SIM卡是移动还是联通

    技术2024-12-08  20

    背景知识 国际移动用户识别码(IMSI:International Mobile Subscriber Identification Number)是区别移动用户的标志,储存在SIM卡中,可用于区别移动用户的有效信息。IMSI由MCC、MNC、MSIN组成,其中MCC为移动国家号码,由3位数字组成,唯一地识别移动客户所属的国家,我国为460;MNC为网络id,由2位数字组成,用于识别移动客户所归属的移动网络,中国移动为00,中国联通为01;MSIN为移动客户识别码,采用等长11位数字构成。唯一地识别国内GSM移动通信网中移动客户。所以要区分是移动还是联通,只需取得SIM卡中的MNC字段即可,在S60 2nd和3rd上都提供这样的api。 // TelephonyAO.h#include <e32base.h>#include <Etel3rdParty.h> class CTelephonyAO : public CActive{public: static CTelephonyAO* NewL();        void GetNetWorkId(TDes& aNetworkId); public: ~CTelephonyAO(); protected: void DoCancel(); void RunL(); private: CTelephonyAO(); void ConstructL();  void GetNetWorkInfo(); private: CTelephony* pTelephony_;  CTelephony::TCancellationRequest cancelRequest_; CTelephony::TNetworkInfoV1 networkInfo_; CTelephony::TNetworkInfoV1Pckg networkInfoPkg_;};#endif// TelephonyAO.cpp#include "TelephonyAO.h" CTelephonyAO::CTelephonyAO() : CActive(EPriorityStandard), networkInfoPkg_(networkInfo_){ CActiveScheduler::Add(this);} CTelephonyAO::~CTelephonyAO(){ delete pTelephony_;} void CTelephonyAO::ConstructL(){ pTelephony_ = CTelephony::NewL();} CTelephonyAO* CTelephonyAO::NewL(){ CTelephonyAO* pSelf = new(ELeave) CTelephonyAO; CleanupStack::PushL(pSelf); pSelf->ConstructL(); CleanupStack::Pop(); return pSelf;} void CTelephonyAO::RunL(){ CActiveScheduler::Stop();} void CTelephonyAO::DoCancel(){ pTelephony_->CancelAsync(cancelRequest_);} void CTelephonyAO::GetNetWorkInfo(){ Cancel(); cancelRequest_ = CTelephony::EGetCurrentNetworkInfoCancel; pTelephony_->GetCurrentNetworkInfo(iStatus, networkInfoPkg_); SetActive(); CActiveScheduler::Start();} void CTelephonyAO::GetNetWorkId(TDes& aNetworkId){ GetNetWorkInfo(); aNetworkId = networkInfo_.iNetworkId;}使用(N70测试通过): TBuf<4> networkId; CTelephonyAO* pTelephony = CTelephonyAO::NewL();CleanupStack::PushL(pTelephony);pTelephony->GetNetWorkId(networkId);CleanupStack::PopAndDestroy(pTelephony);// 下面通过判断networkId是01还是00即可区分移动和联通Related Wiki ArticlesNo related wiki articles found

     

    最新回复(0)