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

KIS*_*_ZE 4 java android listview package-managers android-intent

我希望能够获得手机中安装的所有应用程序的字符串包名称和图标.我做了什么:浏览并找到了这个解决方案

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());
  } 
Run Code Online (Sandbox Code Playgroud)

问题是它显示包和类名作为混合,我无法获得图标.我想要的是向用户显示带有图标的手机上安装的所有应用程序的列表.而且我还需要能够获得包名称List.OnItemClickListener.我假设使用一组具有相同定位的应用程序名称和包名称,我可以做到这一点.但是,我如何获得包名称的应用程序图标和名称.最好作为Array或ArrayList,我可以将其转换为listView对象.如果有任何替代方法,请告诉我.我还是Android的初学者.

请帮忙.

And*_*der 11

请使用以下代码和说明:

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

    }
Run Code Online (Sandbox Code Playgroud)

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