获取android中所有已安装应用的名称、图标和包名

Get the name, icon and package name of all the installed applications in android

我希望能够获取我phone中安装的所有应用程序的字符串包名称和图标。 我做了什么: 浏览并找到此解决方案

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
            final List pkgAppsList = this.getPackageManager().queryIntentActivities(mainIntent, 0);
            for(int counter = 0; counter<=pkgAppsList.size()-1;counter++)
            {
                    Log.e("TAG", pkgAppsList.get(counter).toString());
  } 

问题是它同时显示包和 class 名称,但我无法获取图标。我想要的是向用户显示安装在 phone 上带有图标的所有应用程序的列表。而且我还需要能够使用 List.OnItemClickListener 获取包名称。我假设使用一组具有相同定位的应用程序名称和包名称我可以做到这一点。但是我如何获得应用程序图标和带有包名称的名称。最好是 Array 或 ArrayList,我可以将其转换为 listView 对象。如果有任何替代方法甚至让我知道。 Android.

我还是初学者

请帮忙。

请使用以下代码和说明:

//check this code with some hard work then you will rock
 List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);

    ArrayList<AppInfo> res = new ArrayList<AppInfo>();
    for(int i=0;i<apps.size();i++) {
                    PackageInfo p = apps.get(i);

                    AppInfo newInfo = new AppInfo();
                    newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
                    newInfo.pname = p.packageName;
                    newInfo.versionName = p.versionName;
                    newInfo.versionCode = p.versionCode;
                    newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
                    res.add(newInfo);
                    }
                }

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

    }

有关更多信息,请尝试以下链接: http://javatechig.com/android/how-to-get-list-of-installed-apps-in-android http://developer.android.com/reference/android/content/pm/PackageManager.html

使用 this link from this question. I got the package name. Then using the answer from this 问题我得到了 package/app 图标。现在,一旦我想出阵列适配器来容纳它。我想它已经完成了。

我的代码:

final PackageManager pm = getPackageManager();
List<applicationinfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
//The log is not required so if you want to and I recommend during release you remove that statement.
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Drawable icon = getPackageManager().getApplicationIcon(packageInfo.packageName)
imageView.setImageDrawable(icon);

希望这对所有读者也有帮助。

从包名获取应用程序图标图像

Drawable appicon = getPackageManager().getApplicationIcon("com.example.pkgname");
img.setImageDrawable(appicon);