适用版本:
S60 2nd Edition, S60 3rd Edition
具体方案:
通过以下代码可以判断一个UID为KUidMyAppUid的程序是否运行在前台,若是返回ETrue,若否则返回EFalse。
TBool MyApplication::IsTaskInForegroundL(){
RWsSession& wsSession = CEikonEnv::Static()->WsSession();
CArrayFixFlat<TInt>* wgIds = new (ELeave) CArrayFixFlat<TInt>(2);
CleanupStack::PushL(wgIds);
wsSession.WindowGroupList(0, wgIds);
TInt WgId = (*wgIds)[0];
CleanupStack::PopAndDestroy(); // wgIds
CApaWindowGroupName* wgn = CApaWindowGroupName::NewLC(wsSession, WgId);TUid uid = wgn->AppUid();
CleanupStack::PopAndDestroy();
if (uid == KUidMyAppUid) // Put UID of your application.return ETrue;
else
return EFalse;
}