×
Namespaces

Variants
Actions
Revision as of 09:20, 13 September 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to get current roaming status and notification on network change

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Platform Security
Signing Required: DevCert or Symbian Signed
Capabilities: ReadDeviceData
Article
Created: aficianado_001 (09 Dec 2009)
Last edited: hamishwillee (13 Sep 2012)

The code example 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

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

This page was last modified on 13 September 2012, at 09:20.
78 page views in the last 30 days.
×