androidandroid-adapterandroid-applicationinfo

ApplicationInfo adapter in Android to display only apps with launcher intent


as per title i'm looking for a solution to display only the application with launcher intent. Here is my code to retrieve the app list:

public static List<ApplicationInfo> getInstalledApplication(Context context) {
    PackageManager packageManager = context.getPackageManager();
    List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
    Collections.sort(apps, new ApplicationInfo.DisplayNameComparator(packageManager));
    return apps;
}

Is it possible to add a rule to remove all the packages without launcher intent? Thanks


Solution

  • I managed to solved by myself using a pices of code provided by marcus.ramsden:

    public static List<ApplicationInfo> getInstalledApplication(Context context) {
        PackageManager packageManager = context.getPackageManager();
        List<ApplicationInfo> apps = packageManager.getInstalledApplications(0);
        List<ApplicationInfo> appInfoList = new ArrayList();
        for (ApplicationInfo info : apps) {
            if (packageManager.getLaunchIntentForPackage(info.packageName) != null) {
                appInfoList.add(info);
            }
        }
        Collections.sort(appInfoList, new ApplicationInfo.DisplayNameComparator(packageManager));
        return appInfoList;
    }