×
Namespaces

Variants
Actions

How to detect internet disconnection from application using red key

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: kbalak (31 Mar 2008)
Last edited: hamishwillee (07 Feb 2012)

Contents

Purpose

Whenever an application has an active internet connection and if the user terminates the connection by long pressing the red/end call key, there is no way to capture the choice made by user in the "end data package query" and do the required cleanup. A workaround to this problem is the use of RConnectionMonitor & MConnectionMonitorObserver classes.


Headers to be included:

#include <rconnmon.h>

Link against this libraries:

LIBRARY  ConnMon.lib


The following steps must be implemented

1. Derive your class from MConnectionMonitorObserver and give implementation for virtual function EventL(const CConnMonEventBase &aConnMonEvent)

2.Have a RConnectionMonitor class object in your class and whenever you initiate an internet connection connect your class to Connection Monitor Server using the function:ConnectL()

3.After connecting ,register your class to catch connection monitor events using the function: NotifyEventL(MConnectionMonitorObserver &aObserver)

4.Whenever there is a change in the status of the connection ,the TConnMonEvent events generated by the connection monitor are handled by the implemented EventL() function of the class.

Example Code

Header File

class CExampleClass : public CCoeControl,
public MConnectionMonitorObserver
{
public:
/*
Some Functions
*/

 
//From MConnectionMonitorObserver
void EventL (const CConnMonEventBase &aConnMonEvent);
 
 
private: // Data
RConnectionMonitor iConnectionMonitor;
};

Source File

void CExampleClass::ConstructL( const TRect& aRect )
{
/*
Some Code
*/

 
User::LeaveIfError( iConnectionMonitor.ConnectL() ); //Connecting with server
 
User::LeaveIfError( iConnectionMonitor.NotifyEventL( *this )); //Registering
//with Server.
// Set the main window size
SetRect( aRect );
// Activate the window, which makes it ready to be drawn
ActivateL();
}
 
void CExampleClass::EventL (const CConnMonEventBase &aConnMonEvent)
{
switch ( aConnMonEvent.EventType() )
{
case EConnMonDeleteConnection:
{
// Some Implementation
 
break;
}
case EConnMonNetworkStatusChange:
{
// Some Implementation
 
break;
}
case EConnMonConnectionStatusChange:
{
// Some Implementation
 
break;
}
case EConnMonBearerChange:
{
// Some Implementation
 
break;
}
default:
break;
}
}
This page was last modified on 7 February 2012, at 08:24.
54 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.

×