I want to get a list of Installed apps, but only the ones which have an icon and are launchable . I am making a launcher app and using this:
private List<AppList> getInstalledApps() {
List<AppList> res = new ArrayList<AppList>();
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if ((isSystemPackage(p) == false)) {
String appName = p.applicationInfo.loadLabel(getPackageManager()).toString();
Drawable icon = p.applicationInfo.loadIcon(getPackageManager());
String package_name = p.applicationInfo.packageName;
res.add(new AppList(appName, package_name, icon));
}
}
private boolean isSystemPackage(PackageInfo pkgInfo) {
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true : false;
}
The problem is, to filter out non launchable apps, I have to filter out system apps, which is not the best solution because it also filters out these apps: Camera, Calendar, Calculator etc.
You can check if an app is launchable by
packageManager.getLaunchIntentForPackage(packageName) != null
For icons, you can check if
info.loadIcon(packageManager) != null
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.