0

使用此代码:

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

我可以在 logcat 包信息等中显示。但我想在我的已安装应用程序的活动中显示一个列表,如果可能的话,它的图标和应用程序的名称。可能吗?ps:我正在使用片段

4

3 回答 3

1

看这个演示: 圆形启动器

于 2013-10-22T16:22:51.653 回答
0

以下应该完成获取应用程序列表的工作

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
applications = mPackageManage.queryIntentActivities(intent, PackageManager.GET_META_DATA);
于 2013-10-22T16:28:27.460 回答
0

像这样试试

首先为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;
        }
    }

第2步)

这将为您提供所有安装应用程序的列表以及应用程序名称、图标和包

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

现在你可以在你的适配器类中使用这个List ,

希望这会帮助你。

于 2013-10-22T16:37:09.073 回答