app Icon Lookup - Android App

Android examples for App:App Information

Description

app Icon Lookup

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.util.Log;

public class Main {
    public static Drawable appIconLookup(Context context, String packageName) {

        try {//from w w  w . j av a 2  s.com

            PackageManager pm = context.getPackageManager();
            ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
            return pm.getApplicationIcon(ai);

        } catch (final PackageManager.NameNotFoundException e) {

            e.printStackTrace();
            Log.e("AppsHelper", "Could not find icon for " + packageName);

            return null;

        }

    }
}

Related Tutorials