Get icons of all installed apps in android

前端 未结 5 1321
眼角桃花
眼角桃花 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条回答
  •  生来不讨喜
    2020-12-13 19:53

    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 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 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 of for reference

    OR

    You can download custom launcher code from My Github repository

提交回复
热议问题