List of usage examples for android.content.pm ActivityInfo getIconResource
public final int getIconResource()
From source file:jahirfiquitiva.iconshowcase.tasks.LoadAppsToRequest.java
public Drawable getAppIcon(ActivityInfo info) { Resources resources;/*from w w w . ja va 2 s. c o m*/ try { resources = context.get().getPackageManager().getResourcesForApplication(info.applicationInfo); } catch (PackageManager.NameNotFoundException e) { resources = null; } if (resources != null) { int iconId = info.getIconResource(); if (iconId != 0) { return getAppIcon(resources, iconId); } } return getAppDefaultActivityIcon(); }
From source file:android.support.v7.widget.SuggestionsAdapter.java
/** * Gets the activity or application icon for an activity. * * @param component Name of an activity. * @return A drawable, or {@code null} if neither the acitivy or the application * have an icon set./*w w w .ja va2 s .c o m*/ */ private Drawable getActivityIcon(ComponentName component) { PackageManager pm = mContext.getPackageManager(); final ActivityInfo activityInfo; try { activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA); } catch (NameNotFoundException ex) { Log.w(LOG_TAG, ex.toString()); return null; } int iconId = activityInfo.getIconResource(); if (iconId == 0) return null; String pkg = component.getPackageName(); Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo); if (drawable == null) { Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString()); return null; } return drawable; }