I need to know the list of installed applications that can be launched by the user (for example: Browser, Email, Maps, etc.). I read this question about the getInstalledApplications
method, so I wrote the following code:
final PackageManager pm = getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo app : apps) {
Intent launchIntent = pm.getLaunchIntentForPackage(app.packageName);
if (launchIntent != null) {
Log.d(LOG_TAG, "getApplicationLabel: " + pm.getApplicationLabel(app));
Log.d(LOG_TAG, "loadLabel: " + app.loadLabel(pm));
Log.d(LOG_TAG, "packageName: " + app.packageName);
Log.d(LOG_TAG, "name: " + app.name);
}
}
In this way I get the list of applications that can be launched. Each of these applications is characterized by a package name, so if I want to start one of these, just get the launch intent for the package by specifying the package name.
This means that each package has at most an activity that can be launched, so each of the applications (which are returned by the getInstalledApplications
method) should have a unique package name. Is that correct?