title: Android: How to get a list of installed activities, as they appear in launcher, without duplicates
body: <p>I am writing an app that allows user to view the list of installed apps, select one of them and then start it on schedule. Using tutorials from stackoverflow i managed to figure out how to get a list of installed activities, their package names and icons(i.e. <a href="https://stackoverflow.com/questions/7116029/android-simple-way-to-display-installed-apps-or-tutorial">here</a> - several ways to do it). Just in case, this is how i start activities, it works flawlessly, no problem here:</p>
  
  <pre><code>Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
  launchIntent.setAction(Intent.ACTION_MAIN);
  launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(launchIntent);
  </code></pre>
  
  <p>The problem is with retrieving a list of installed apps. I've found two ways to get a list of installed applications:</p>
  
  <p>1) use </p>
  
  <pre><code>PackageManager pm = getPackageManager();
  List&lt;ApplicationInfo&gt; apps = pm.getInstalledApplication(PackageManager.GET_META_DATA) 
  </code></pre>
  
  <p>and from each element from <code>apps</code> you can get it's package name and package label(app names).</p>
  
  <p>2) use  </p>
  
  <pre><code>PackageManager pm = getPackageManager();    
  Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  List&lt;ResolveInfo&gt; resolveInfos = packageManager.queryIntentActivities(mainIntent, 0);
  for(ResolveInfo info : resolveInfos) {
      ApplicationInfo applicationInfo = info.activityInfo.applicationInfo;
      //...
      //get package name, icon and label from applicationInfo object    
  }
  </code></pre>
  
  <p>There is a problem with <strong>first</strong> method: it returns all installed packages, including system services, which may not contain any activity and are therefore not launchable. Here's a screenshot with an example:
  <img src="https://i.stack.imgur.com/N1HCo.png" alt="app list with packages"></p>
  
  <p>All the items above that have no icons are not launchable.</p>
  
  <p>There is a problem with the <strong>second</strong> approach as well: Several items in the list have duplicates:
  <img src="https://i.stack.imgur.com/I0QrS.png" alt="app list with duplicates"></p>
  
  <p>When i set up a breakpoint in debugger i see, that these "Maps" items have different activity names ("com.google.android.maps.MapsActivity", "com.google.android.maps.LatitudeActivity", "com.google.android.maps.PlacesActivity" etc.). </p>
  
  <p>I decided to use the second approach, because it gives a list that is more suitable for my needs, but i can't find a way to filter out the duplicates and only show the default activity for the app, as they appear in the Launcher(you only see one 'Maps' in your phone's list of apps, not four). I've tried filtering out system apps through <code>ApplicationInfo.FLAG_SYSTEM</code>, but this removes many apps that i want to have, including Maps and other preinstalled apps. I've tried using <code>PackageManager.MATCH_DEFAULT_ONLY</code> flag when executing queryIntentActivities, but this also filters out many apps, leaving just a few. </p>
  
  <p>I'm kinda lost here, and i don't know what to do. I've read all the questions on stackoverflow about retrieving a list of installed apps, but this issue has never been brought up. Please, help anyone? How do i retrieve a list of installed launchable apps that has no duplicates?</p>