Android 中的应用程序包名称中的应用程序名称和应用程序图标

Application Name And Application Icon from Application Package Name In Android

我已经通过以下代码存储了一个应用程序的包名。

 mActivityManager = (ActivityManager)this.context.getSystemService(Context.ACTIVITY_SERVICE);

       for (ApplicationInfo packageInfo : packages)
       {
            String pck = packageInfo.packageName;
            if(pck.startsWith("com.google") )
            {
                 app = new APP(R.drawable.ic_launcher,packageInfo.packageName);
                 application_package.add(app);
                 continue;
            }
            if((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM)==1)continue;
            if(packageInfo.packageName.equals("com.walton.taskkiller")) continue;
            app = new APP(R.drawable.ic_launcher,packageInfo.packageName);
            application_package.add(app);
               }

现在我想知道应用程序名称和应用程序图标。如何从应用程序包中获取应用程序名称和应用程序图标?

首先获取包管理器的实例:

PackageManager packageManager = getPackageManager();

现在通过ApplicationInfo实例获取应用名称和应用图标:

String appName = applicationInfo.loadLabel(packageManager)

Drawable appIcon = applicationInfo.loadIcon(packageManager)