如何获取应用程序图标(转)

Following code sample can be used to retrieve application icons

Hearders Required:

#include <fbs.h> //CFbsBitmap
#include <aknsskininstance.h> //MAknsSkinInstance
#include <aknsutils.h> //AknsUtils

Library required:

LIBRARY   fbscli.lib ///CFbsBitmap
LIBRARY aknskins.lib aknskinsrv.lib aknswallpaperutils.lib //MAknsSkinInstance ,AknsUtils

Source Code:

CGulIcon* CMyClass::GetApplicationIconL(const TUid& aAppUID)
{
CFbsBitmap* AppIcon(NULL);
CFbsBitmap* AppIconMsk(NULL);
 
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
 
AknsUtils::CreateAppIconLC(skin,aAppUID, EAknsAppIconTypeContext,AppIcon,AppIconMsk);
CleanupStack::Pop(2);
 
return CGulIcon::NewL(AppIcon,AppIconMsk);
}

You could get application UIDs from TApaAppInfo, which you could get for example by using the code sample shown in here

A known issue:

The utility function doesn't need any capability if you are creating app icons of Symbian OS C++ applications. But when getting the app icons of Java applications the AllFiles capability is required. As it is less possible for a normal application to have AllFiles capability, it is suggested to add error handling code like this:

// first try to use the utility function
TRAPD(err, AknsUtils::CreateAppIconL(...))
if(err!=KErrNone)
{
// if it failed then use the traditional way
err = RApaLsSession::GetAppIcon();
}
if(err!=KErrNone)
{
// if both of them failed then
// load a default icon for the application
...
}

References How to get Application Icon using RApaLsSession

 

How to get Application Icon using RApaLsSession

#include <APGCLI.H>
Link against: apgrfx.lib
RApaLsSession aLs;
User::LeaveIfError(aLs.Connect());
CleanupClosePushL(aLs);
CArrayFixFlat<TSize>* array=new(ELeave)CArrayFixFlat<TSize>(3);
CleanupStack::PushL(array);
User::LeaveIfError(aLs.GetAppIconSizes(uid,*array));
for(TInt i=0;i < array->Count();i++)
{
CApaMaskedBitmap* iconBySize=CApaMaskedBitmap::NewLC();
if(aLs.GetAppIcon(KUidTestApp,(*array)[i],*iconBySize) == KErrNone)
//icon is now in iconBySize
CleanupStack::PopAndDestroy(iconBySize);
}
CleanupStack::PopAndDestroy(array);
CleanupStack::PopAndDestroy(&aLs);
posted @ 2011-06-01 14:05  冰岛  阅读(1112)  评论(0编辑  收藏  举报