如何获取IMSI号

CImsiReader example illustrates how to read IMSI (SIM card's identity number, which has nearly nothing to do with the MSISDN that is the phone number used for calling) in 3rd Edition Symbian devices. Note that this code will most likely not work in the emulator, thus you should only use it in real devices.


1.1 Link against:
etel3rdparty.lib


1.2 Capability require:
CAPABILITY  ReadDeviceData


1.3 IMSI_Getter.cpp


#include "Imsi_Getter.h"  //LP: added #include for Imsi_Getter.h header file
 
CImsiReader* CImsiReader::NewL(MImsiObserver* aObserver)
    {
    CImsiReader* self = NewLC(aObserver);
    CleanupStack::Pop(self);
    return self;
    } 
 
CImsiReader* CImsiReader::NewLC(MImsiObserver* aObserver)
    {
    CImsiReader* self = new (ELeave) CImsiReader(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    } 
 
CImsiReader::CImsiReader(MImsiObserver* aObserver)
:CActive(0),iObserver(aObserver),iImsiV1Pkg(iImsiV1)
{
}
 
CImsiReader::~CImsiReader()
{
 Cancel();
 delete iTelephony;
 
}
 
void CImsiReader::ConstructL(void)

 CActiveScheduler::Add(this);
 
 iTelephony = CTelephony::NewL();
 iTelephony->GetSubscriberId(iStatus,iImsiV1Pkg);
 SetActive();
}
 
void CImsiReader::DoCancel()
{
 iTelephony->CancelAsync(CTelephony::EGetSubscriberIdCancel);

 
void CImsiReader::RunL()
{
        //LP: added ";" and replaced iTelephony with iObserver
 iObserver->GotIMSIL(iImsiV1.iSubscriberId,iStatus.Int());
}


1.4 IMSI_Getter.h


#include <Etel3rdParty.h>
 class MImsiObserver
 {
 public: // New methods
  virtual void GotIMSIL(const TDesC& aIMSI, TInt aError) = 0;
 };
 
 class CImsiReader : public CActive
     {
 
 public:
  static CImsiReader* NewL(MImsiObserver* aObserver);
  static CImsiReader* NewLC(MImsiObserver* aObserver);
  ~CImsiReader();
 protected: 
  void DoCancel();
  void RunL();
 private:
  CImsiReader(MImsiObserver* aObserver);
     void ConstructL(void);
 private:
  MImsiObserver*      iObserver;
  CTelephony*      iTelephony;
  CTelephony::TSubscriberIdV1  iImsiV1;   
     CTelephony::TSubscriberIdV1Pckg iImsiV1Pkg;
     };


1.5 NB: Note for console applications
In a Console application you have to create a Active scheduler (to run active objects) before calling the code above or the code above will not work e.g.
LOCAL_C void ApplicationL()
 {
  CIMSIApp::GetIMSI(iIMSI);
 }
 
LOCAL_C void Main()
 {
  // Create active scheduler (to run active objects)
  CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
  CleanupStack::PushL(scheduler);
  CActiveScheduler::Install(scheduler);
  ApplicationL();
  CleanupStack::PopAndDestroy(scheduler);
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值