首先介绍下背景知识:
SIM卡唯一标识:IMSI 国际移动用户识别码(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。
Code: // TelephonyAO.h
#include **
#include **
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_;
};
/* .cpp */ // 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;
}
用法:
TBuf<4> networkId;
CTelephonyAO* pTelephony = CTelephonyAO::NewL();
CleanupStack::PushL(pTelephony);
pTelephony->GetNetWorkId(networkId);
CleanupStack::PopAndDestroy(pTelephony); // 下面通过判断networkId是01还是00即可区分移动和联通
(注: 移动或者联通新号码断非00和01,可以根据具体的SIM卡测试归类一下)