×
Namespaces

Variants
Actions
Revision as of 08:30, 11 December 2009 by mayankkedia (Talk | contribs)

How to get current roaming status and notification on network change

From Nokia Developer Wiki
Jump to: navigation, search

The code snippet below demonstrates how to find out the current SIM status(roaming or in home network) and get notification on every network change. The application must be Symbian Signed, since it requires the ReadDeviceData capability. The programmer must use an active object because the calls are asynchronous.

Header Required:

#include<etel3rdparty.h>

Library Required:

LIBRARY  etel3rdparty.lib

Capability Required:

Capability  ReadDeviceData

NetRegister.h

#ifndef CNETREGISTER_H__
#define CNETREGISTER_H__
 
#include <Etel3rdParty.h> // link against Etel3rdParty.lib
 
//Enumeration to get more control on initial registration status or network changed notification
enum TNetStatus
{
EOperationNone,
ENetworkInitialRegInfo,
ENetworkChangeRegInfo
};
 
class CNetRegister : public CActive
{
 
public:
 
// static constructor + destructor
static CNetRegister* NewL();
~CNetRegister();
 
public:
 
void IssueRequest();
void GetNetworkRegistration();
 
protected: // from CActive
virtual void DoCancel();
virtual void RunL();
 
private: // private constructors
 
CNetRegister();
void ConstructL();
 
private: // data
CTelephony* iTelephony;
CTelephony::TNetworkRegistrationV1 iNetworkRegistrationV1;
CTelephony::TNetworkRegistrationV1Pckg iNetworkRegistrationV1Pckg;
TNetStatus iNetStatus;
};
 
#endif CNETREGISTER_H__

NetRegister.cpp

#include "NetRegister.h"
 
CNetRegister* CNetRegister::NewL()
{
CNetRegister* self = new (ELeave) CNetRegister();
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(); // self
return self;
}
 
 
CNetRegister::CNetRegister(): CActive(EPriorityHigh),iNetworkRegistrationV1Pckg(iNetworkRegistrationV1)
{
 
}
void CNetRegister::ConstructL()
{
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this);
GetNetworkRegistration();
}
 
 
CNetRegister::~CNetRegister()
{
Cancel();
delete iTelephony;
}
 
 
void CNetRegister::RunL()
{
if( iStatus == KErrNone )
{
switch(iNetStatus)
{
//Network registration changed notification.
case ENetworkChangeRegInfo:
{
CTelephony::TRegistrationStatus regStatus = iNetworkRegistrationV1.iRegStatus;
if(regStatus==CTelephony::ERegisteredRoaming)
{
//Network changed to Roaming
}
else if(regStatus==CTelephony::ERegisteredOnHomeNetwork)
{
//Network changed to Home network
}
}
break;
//Initial status of network registration. Do first time network status task like saving any network data etc here.....
case ENetworkInitialRegInfo:
{
CTelephony::TRegistrationStatus regStatus = iNetworkRegistrationV1.iRegStatus;
if(regStatus==CTelephony::ERegisteredRoaming)
{
//Initially in Roaming
}
else if(regStatus==CTelephony::ERegisteredOnHomeNetwork)
{
//Initially in Home network
}
}
break;
default:
break;
}
 
}
else
{
// Handle errors
}
IssueRequest();
}
 
 
void CNetRegister::DoCancel()
{
iTelephony->CancelAsync(CTelephony::ENetworkRegistrationStatusChangeCancel);
iTelephony->CancelAsync(CTelephony::EGetNetworkRegistrationStatusCancel);
}
 
 
void CNetRegister::IssueRequest()
{
iNetStatus = ENetworkChangeRegInfo;
iTelephony->NotifyChange( iStatus,
CTelephony::ENetworkRegistrationStatusChange,
iNetworkRegistrationV1Pckg);
SetActive();
}
 
void CNetRegister::GetNetworkRegistration()
{
iNetStatus = ENetworkInitialRegInfo;
iTelephony->GetNetworkRegistrationStatus(iStatus, iNetworkRegistrationV1Pckg);
SetActive();
}

Related Links

73 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×