Search code examples
androidandroid-package-managers

ApplicationInfo Vs PackageInfo vs ResolveInfo


For all the installed apps on a phone, I need to access the:

  • name
  • icon
  • google play url from where the app can be installed

I've looked at ApplicationInfo but that doesn't seem to provide this information to me. I've heard of PackageInfo and ResolveInfo, however I am quite confused what is the difference between them and which one should be used where? Lastly, what can I use to find the above three details about the installed apps ?

For package names, I get things like com.something.some

This is the code I am using to get apps:

final PackageManager pm = getPackageManager();
ArrayList<ApplicationData> listAppData = new ArrayList<ApplicationData>();

//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

for (ApplicationInfo packageInfo : packages) {
    listAppData.add(new ApplicationData(packageInfo));
}

ApplicationData is my own class where I extract information from packageInfo


Solution

  • This function will return a list of apps with icon, name and package.

    With the package you can build the url with:

    https://play.google.com/store/apps/details?id= <PACKAGE>
    

    See:

    public class Application {
    
        private String packageName;
        private String name;
        private Drawable icon;
        private boolean checked;
    ...
    
    private List<Application> getAllApplications(Context context)
                throws NameNotFoundException {
    
            PackageManager packageManager = context.getPackageManager();
            List<PackageInfo> packages = packageManager.getInstalledPackages(0);
    
            List<Application> myPackages = new ArrayList<Application>();
    
            for (PackageInfo pack : packages) {
                if (pack.versionName == null) {
                    continue;
                }
    
                Application newPack = new Application();
                newPack.setPackageName(pack.packageName);
                newPack.setName(pack.applicationInfo.loadLabel(packageManager)
                        .toString());
                newPack.setIcon(pack.applicationInfo.loadIcon(packageManager));
    
                myPackages.add(newPack);
            }
    
            return myPackages;
        }