You Are Here:

Community: Wiki

This page was last modified on 13 May 2009, at 09:24.

Notification of application change

From Forum Nokia Wiki


The following example shows how to get notified of an application change, and once the change has been observed, how to get the application name and other details of the application that has come on top.

This kind of code is needed when we are writing some logic in the code which would do different things based on what application is in the foreground. For instance if standby application is on top show a global note to the user or something like that.

Header file required:

#include <cntdb.h>

Add following line to your .mmp file.

LIBRARY   ws32.lib apgrfx.lib

Add following lines in AppChangeNotifier.h file.

#include <W32STD.H>
 
class MAppChangeObserver
{
public:
/**
* Virtual function, implemented elsewhere
*/

virtual void NotifyAppChangeL(TBool aStandbyInFront) = 0;
};
 
class CAppChangeNotifier: public CActive
{
private:
CAppChangeNotifier(MAppChangeObserver& aAppChangeObserver);
void ConstructL();
 
public:
static CAppChangeNotifier* NewL(MAppChangeObserver& aAppChangeObserver);
~CAppChangeNotifier();
void Start();
 
private:
// From CActive
void DoCancel();
void RunL();
TInt RunError(TInt aError);
 
private:
RWsSession iWs;
RWindowGroup iWindowGroup;
MAppChangeObserver& iAppChangeObserver;
};

Add following lines in AppChangeNotifier.cpp file.

#include <APGWGNAM.H>
 
// User Include
#include "AppChangeNotifier.h"
CAppChangeNotifier::CAppChangeNotifier(MAppChangeObserver& aAppChangeObserver)
:CActive(EPriorityIdle), iAppChangeObserver(aAppChangeObserver), iTodayInForeground(EFalse)
{
}
 
CAppChangeNotifier* CAppChangeNotifier::NewL(MAppChangeObserver& aAppChangeObserver)
{
CAppChangeNotifier* self = new (ELeave)CAppChangeNotifier(aAppChangeObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
 
void CAppChangeNotifier::ConstructL()
{
CActiveScheduler::Add(this);
 
User::LeaveIfError(iWs.Connect());
 
// Windows Group
iWindowGroup = RWindowGroup(iWs);
User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast<TUint32> (&iWindowGroup), EFalse));
iWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
iWindowGroup.EnableReceiptOfFocus(EFalse);
User::LeaveIfError(iWindowGroup.EnableFocusChangeEvents());
}
 
CAppChangeNotifier::~CAppChangeNotifier()
{
Cancel();
iWindowGroup.Close();
iWs.Close();
}
 
void CAppChangeNotifier::Start()
{
iWs.EventReady(&iStatus);
SetActive();
}
 
void CAppChangeNotifier::DoCancel()
{
iWs.EventReadyCancel();
}
 
void CAppChangeNotifier::RunL()
{
// Get the event from the window server session iWs
TWsEvent wsEvent;
iWs.GetEvent(wsEvent);
// Get the event type: types are defined in TEventCode
switch (wsEvent.Type())
{
// Window-group related event types
case EEventFocusGroupChanged:
{
TInt wgid = iWs.GetFocusWindowGroup();
CApaWindowGroupName* gn = CApaWindowGroupName::NewLC(iWs, wgid);
TBuf<80> appName = gn->Caption();
_LIT(KStandby, "Standby mode");
if(appName.Compare(KStandby) == 0)
{
iAppChangeObserver.NotifyAppChangeL(ETrue);
}
else
{
iAppChangeObserver.NotifyAppChangeL(EFalse);
}
CleanupStack::PopAndDestroy(gn);
}
break;
}
Start();
}
 
TInt CAppChangeNotifier::RunError(TInt aError)
{
return KErrNone;
}

Add following lines in YourClass.h file.

class CYourClass:public CBase, public MAppChangeObserver
{
public:
void NotifyAppChangeL(TBool aStandbyInFront);
public:
CAppChangeNotifier* iAppChangeNotifier ;
};

Add following lines in YourClass.cpp file.

// Register for Ws Changes to be notified
iAppChangeNotifier = CAppChangeNotifier::NewL(*this);
 
void CYourClass::NotifyAppChangeL(TBool aStandbyInFront)
{
// Do something
}

Added by - Mayank on 13/05/2009

Link

TSS000754 - Getting notifications of focus change and launching of other applications

How to determine if a certain application is in the foreground?

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fInstallingE5fJavaE5fappsE5fandE5fWE52TE5fwidgetsE5fusingE5fsisE5ffilesX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
RDF Facets: qfnZuserE5FtagQSxeeventfocusgroupchangedX qfnZuserE5FtagQSxgetE20focusE20applicationX qfnZuserE5FtagQSxgetfocuswindowgroupX