in simple terms
These classes points to same source AndroidManifest.xml of an Application.
The difference is in terms of Access Level nothing more than that.
Sometimes you need all the information but most of the times you need
to deal with specific information only. In those cases there is no need
to parse all the content of the manifest file.
PackageInfo
has access to all the content of the Manifest. This can be used if you want to read every detail of Manifest
ApplicationInfo
has access to Application Tag of Manifest file thus ignoring all the irrelevant area of the file.
ResolveInfo has access to intent-filters thus ignoring all the other details.
ApplicationInfo and ResolveInfo are just handy classes that we can use according to our requirement.
From the docs and some examples on how to use them:
ApplicationInfo documentation:
Information you can retrieve about a particular application. This
corresponds to information collected from the AndroidManifest.xml's
tag.
Example:
ApplicationInfo.FLAG_SYSTEM
tag to filter out System Apps
if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
{
// system app
}
PackageInfo documentation:
Overall information about the contents of a package. This corresponds
to all of the information collected from AndroidManifest.xml.
Example: To get versionCode of the app
long versionCode = 0L;
if (Build.VERSION.SDK_INT >= VERSION_CODES.P) {
versionCode = packageManager.getPackageInfo(packageName, 0).getLongVersionCode();
} else {
versionCode = (Long) packageManager.getPackageInfo(packageName, 0).getVersionCode();
}
ResolveInfo documentation:
Information that is returned from resolving an intent against an
IntentFilter. This partially corresponds to information collected from
the AndroidManifest.xml's tags.
Example:
final Intent newIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( newIntent, 0);
for (ResolveInfo rInfo : list) {
System.out.println("Installed Applications supporting category launcher " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
The above example will help you to get ResolveInfo
to start a application
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>)
pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}