Android APK Icon Get getAppIcon(Context c, int uid)

Here you can find the source of getAppIcon(Context c, int uid)

Description

get App Icon

Declaration

public static Drawable getAppIcon(Context c, int uid) 

Method Source Code

//package com.java2s;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable getAppIcon(Context c, int uid) {
        PackageManager pm = c.getPackageManager();

        Drawable icon = null;/*from  w w w .  j  av  a2  s .  c  o  m*/
        try {

            String name = pm.getPackagesForUid(uid)[0];

            icon = (Drawable) getAppInfo(c, name).loadIcon(pm);

        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NullPointerException e) {
            icon = null;
        }
        return icon;
    }

    private static ApplicationInfo getAppInfo(Context c, String name)
            throws NameNotFoundException {
        PackageManager pm = c.getPackageManager();
        return pm.getApplicationInfo(name,
                PackageManager.GET_UNINSTALLED_PACKAGES);
    }
}

Related

  1. getAppIcon(Context c, int uid)
  2. getDensityOptimizedIconSize(final Context context)
  3. getDensityOptimizedIconSizeDrawable( final Context myAppContext, final Context targetPackageContext, final int resId)
  4. showUninstallAPKIcon(Context c, String apkPath)