Get icons of all installed apps in android

前端 未结 5 1310
眼角桃花
眼角桃花 2020-12-13 19:02

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 i

5条回答
  •  萌比男神i
    2020-12-13 19:58

    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 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();
                }
            }
    

提交回复
热议问题