简体   繁体   English

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

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

I want to be able to get the string package name and icon of all the applications installed in my phone. 我希望能够获得手机中安装的所有应用程序的字符串包名称和图标。 What I have done: Browsed and found this solution 我做了什么:浏览并找到了这个解决方案

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

The problem is that it displays package and class name as as a as a mix and I can't get the icon. 问题是它显示包和类名作为混合,我无法获得图标。 What I want is to show the user a list of all the applications installed on the phone with the icon. 我想要的是向用户显示带有图标的手机上安装的所有应用程序的列表。 And I also need to be able to get the package name with a List.OnItemClickListener . 而且我还需要能够使用List.OnItemClickListener获取包名。 I assume that using an array of app names and package name which are of same positioning I can do that. 我假设使用一组具有相同定位的应用程序名称和包名称,我可以做到这一点。 But how would I get the app icon and name with package name. 但是,我如何获得包名称的应用程序图标和名称。 Preferably as an Array or ArrayList that I can convert into a listView object. 最好作为Array或ArrayList,我可以将其转换为listView对象。 If there is any alternative method even let me know. 如果有任何替代方法,请告诉我。 I am still a beginner in Android. 我还是Android的初学者。

And please do help. 请帮忙。

Please use the below code and directions: 请使用以下代码和说明:

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

    }

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

Using this link from this question. 使用这种从链接这个问题。 I got the package name. 我得到了包裹名称。 Then using the answer from this question I got the package/app icon. 然后使用这个问题的答案我得到了包/ app图标。 Now as soon as I figure the array adapter to accommodate this. 现在我一想到阵列适配器就可以容纳这个。 I guess its done then. 我想它完成了。

My Code: 我的代码:

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

Hope this helps all readers as well. 希望这也有助于所有读者。

get appliction icon image from package name 从包名称获取应用程序图标图像

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM