Get icons of all installed apps in android
Asked Answered
R

5

34

I want to get icons of my all installed apps. Can I get that icons using package manager? Is there any function for it? Or any other way to get icons of all installed apps in bitmap?

Thanks!

Rectus answered 22/5, 2012 at 5:23 Comment(1)
Since Android 3.0 you might want to get a bigger launcher icon that you can't get the way you described. If so, perhaps my answer to question below can help you: https://mcmap.net/q/451311/-getting-app-icon-in-android/…Nolpros
P
49
try {
    String pkg = "com.app.my";//your package name
    Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
    imageView.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ne) {

}

Check here for more details.

Peasant answered 22/5, 2012 at 5:28 Comment(2)
Not working with few apps like FB, chrome in android PLarrainelarrie
causing outOfMemoryErrorHerv
T
10

Above answers are pretty good.

Your Question is:- Get icons of all installed apps in android? you want list of install apps icon

Here is the code which help you to get install apps list with Application (icons,packages names).

**Declare variable in your Activity**

private CustomAppListAdapter customAppListAdapter;
private ArrayList<AppListMain> appListMainArrayList;
private AppListMain appListMain;

Just call below function loadApps() in your Activity onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_app_list);
    loadApps();
    
}

public void loadApps() {
    try {
        packageManager = getPackageManager();
        appListMainArrayList = new ArrayList<>();
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);

        for (ResolveInfo resolveInfo : resolveInfoList) {
            AppListMain appListMain = new AppListMain();
            appListMain.setAppIcon(resolveInfo.activityInfo.loadIcon(packageManager));
            appListMain.setAppName(resolveInfo.loadLabel(packageManager).toString());
            appListMain.setAppPackage(resolveInfo.activityInfo.packageName);
            appListMainArrayList.add(appListMain);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Here is Link for reference

OR

You can download custom launcher code from My Github repository

Tarnopol answered 8/5, 2018 at 6:49 Comment(0)
V
5

I find it the easiest way:

private List<ResolveInfo> installedApps() {
    final Intent main_intent = new Intent(Intent.ACTION_MAIN, null);
    main_intent.addCategory(Intent.CATEGORY_LAUNCHER);
    return package_manager.queryIntentActivities(main_intent, 0);
}

Now to get the icons, use this:

for(ResolveInfo ri : installedApps()) { 
    // to get drawable icon -->  ri.loadIcon(package_manager)
}
Virilism answered 3/11, 2014 at 16:58 Comment(0)
D
4

Try this way: Make a class called PackageInformation:

public class PackageInformation {

    private Context mContext;

    public PackageInformation(Context context) {
        mContext = context;
    }

    class InfoObject {
        public String appname = "";
        public String pname = "";
        public String versionName = "";
        public int versionCode = 0;
        public Drawable icon;


        public void InfoObjectAggregatePrint() { //not used yet
            Log.v(appname, appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
        }

    }

    private ArrayList < InfoObject > getPackages() {
        ArrayList < InfoObject > apps = getInstalledApps(false);
        final int max = apps.size();
        for (int i = 0; i < max; i++) {
            apps.get(i).prettyPrint();
        }
        return apps;
    }

    public ArrayList < InfoObject > getInstalledApps(boolean getSysPackages) {
        ArrayList < InfoObject > res = new ArrayList < InfoObject > ();
        List < PackageInfo > packs = mContext.getPackageManager().getInstalledPackages(0);
        for (int i = 0; i < packs.size(); i++) {
            PackageInfo p = packs.get(i);
            if ((!getSysPackages) && (p.versionName == null)) {
                continue;
            }
            InfoObject newInfo = new InfoObject();
            newInfo.appname = p.applicationInfo.loadLabel(mContext.getPackageManager()).toString();
            newInfo.pname = p.packageName;
            newInfo.versionName = p.versionName;
            newInfo.versionCode = p.versionCode;
            newInfo.icon = p.applicationInfo.loadIcon(mContext.getPackageManager());
            res.add(newInfo);
        }
        return res;
    }

}

tuck this away somewhere and now to access the info from your working Activity class do this:

PackageInformation androidPackagesInfo = new PackageInformation(this);
ArrayList < InfoObject > appsData = androidPackagesInfo.getInstalledApps(true);

for (InfoObject info: appsData) {
    Toast.makeText(MainActivity.this, info.appname, 2).show();
    Drawable somedrawable = info.icon;

}
Dinodinoflagellate answered 11/3, 2013 at 0:1 Comment(0)
D
1

Here below is the code with which you can get the icons of all installed Apps.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            try {
                // try getting the properly colored launcher icons
                LauncherApps launcher = (LauncherApps) this.getSystemService(LAUNCHER_APPS_SERVICE);
                List<LauncherActivityInfo> activityList = launcher.getActivityList(packageName, android.os.Process.myUserHandle());
                drawable = activityList.get(0).getBadgedIcon(0);
            } catch (Exception e) {
            }
        }

        if (drawable == null) {

            try {
                getPackageManager().getApplicationIcon(packageName);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
Donnadonnamarie answered 11/7, 2018 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.