I asked a similar question to this earlier this week but I\'m still not understanding how to get a list of all installed applications and then pick one to run.
I\'v
The idea behind this solution is that the main activity of every system app does not have a custom activity icon. This method gives me an excellent result:
public static Set<PackageInfo> getInstalledApps(Context ctx) {
final PackageManager packageManager = ctx.getPackageManager();
final List<PackageInfo> allInstalledPackages = packageManager.getInstalledPackages(PackageManager.GET_META_DATA);
final Set<PackageInfo> filteredPackages = new HashSet();
Drawable defaultActivityIcon = packageManager.getDefaultActivityIcon();
for(PackageInfo each : allInstalledPackages) {
if(ctx.getPackageName().equals(each.packageName)) {
continue; // skip own app
}
try {
// add only apps with application icon
Intent intentOfStartActivity = packageManager.getLaunchIntentForPackage(each.packageName);
if(intentOfStartActivity == null)
continue;
Drawable applicationIcon = packageManager.getActivityIcon(intentOfStartActivity);
if(applicationIcon != null && !defaultActivityIcon.equals(applicationIcon)) {
filteredPackages.add(each);
}
} catch (PackageManager.NameNotFoundException e) {
Log.i("MyTag", "Unknown package name " + each.packageName);
}
}
return filteredPackages;
}