0

Using this code:

final PackageManager pm = getActivity().getPackageManager();
        //get a list of installed apps.
        List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

        for (ApplicationInfo packageInfo : packages) {
            Log.d(TAG, "Installed package :" + packageInfo.packageName);
            Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 

I can display in the logcat package infos etc.. But i want display a list in my activity of installed apps with its icon if possible and the name of application. Is it possible? ps: i'm using fragments

David_D
  • 1,404
  • 4
  • 31
  • 65
  • possible duplicate of [How to launch applications from another application?](http://stackoverflow.com/questions/16104942/how-to-launch-applications-from-another-application) – CommonsWare Oct 22 '13 at 16:23
  • not at all.. I don't want launch the application but only show a list with icon of app and its name.. – David_D Oct 22 '13 at 16:30
  • You can use Alex Lockwood Loaders [tutorial](http://www.androiddesignpatterns.com/2012/09/tutorial-loader-loadermanager.html). Sample app in it shows apps list. – Bracadabra Oct 22 '13 at 16:40
  • full tutorial http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/ – Maulik Sheth Oct 22 '13 at 16:55

3 Answers3

1

See this demo: Circle launcher

resource8218
  • 1,445
  • 1
  • 20
  • 33
0

Following should do the job of getting the list of applications

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
applications = mPackageManage.queryIntentActivities(intent, PackageManager.GET_META_DATA);
the100rabh
  • 4,077
  • 4
  • 32
  • 40
0

Try like this,

First create a model for PackageItem

public class PackageItem {

        private Drawable icon;

        private String name;

        private String packageName;

        public String getPackageName() {
            return packageName;
        }

        public void setPackageName(String packageName) {
            this.packageName = packageName;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Drawable getIcon() {
            return icon;
        }

        public void setIcon(Drawable icon) {
            this.icon = icon;
        }
    }

Step 2)

This will give you list of all install application with Application Name,Icon and Package also

public List<PackageItem> getInstalledApplication(){

PackageManager appInfo = getPackageManager();
            List<ApplicationInfo> listInfo = appInfo.getInstalledApplications(0);
            Collections.sort(listInfo, new ApplicationInfo.DisplayNameComparator(appInfo));

            List<PackageItem> data = new ArrayList<PackageItem>();

            for (int index = 0; index < listInfo.size(); index++) {
                try {
                    ApplicationInfo content = listInfo.get(index);
                    if ((content.flags != ApplicationInfo.FLAG_SYSTEM) && content.enabled) {
                        if (content.icon != 0) {
                            PackageItem item = new PackageItem();
                            item.setName(getPackageManager().getApplicationLabel(content).toString());
                            item.setPackageName(content.packageName);
                            item.setIcon(getPackageManager().getDrawable(content.packageName, content.icon, content));
                            data.add(item);
                        }
                    }
                } catch (Exception e) {

                }
            }
      return data;
   }

Now You can use this List in your adapter class,

Hope this will help you.

Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
  • and, so, have i to create an adapter class? i can't insert theese values in a listview directly? – David_D Oct 22 '13 at 16:49
  • @David_D you will show it in ListView, so you need Adapter so that you can present the Application name with Icon. – Amit Gupta Oct 22 '13 at 16:51