title: getLaunchIntentForPackage is null for some apps
body: <p>I'm building a service that sends a list of installed apps from an Android TV or a Fire TV to a mobile phone. The phone then sends back the package name of the app it wants to launch and the service launches it. </p>
  
  <p>This is the code that creates the list</p>
  
  <pre><code>public List&lt;InstalledApp&gt; GetInstalledApps(boolean isAndroid) {
      PackageManager pm = getPackageManager();
      List&lt;ApplicationInfo&gt; allPackages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
      List&lt;InstalledApp&gt; userPackages = new ArrayList&lt;InstalledApp&gt;();
  
      for (ApplicationInfo packageInfo : allPackages) {
  
          if (isSystemPackage(packageInfo)) continue;
  
          InstalledApp app = new InstalledApp();
          app.setPackageName(packageInfo.packageName);
          app.setAppName(pm.getApplicationLabel(packageInfo).toString());
          if (!isAndroid) {
              app.setIcon(pm.getApplicationIcon(packageInfo));
          }
          app.setAccentColor(getAccentColor(pm.getApplicationIcon(packageInfo)));
  
  
          userPackages.add(app);
      }
  
      return userPackages;
  }
  </code></pre>
  
  <p>This is how I launch the apps</p>
  
  <pre><code>public void launchApp(String packageName) {
      PackageManager pm = getPackageManager();
      Intent intent = pm.getLaunchIntentForPackage(packageName);
      startActivity(intent);
  }
  </code></pre>
  
  <p>On the Fire TV everything works perfectly but on the Android TV the intent for many of the apps is always null. These are just a few.</p>
  
  <ul>
  <li>com.haystack.android</li>
  <li>com.netflix.ninja</li>
  <li>tv.pluto.android</li>
  <li>com.bamnetworks.mlbtv</li>
  </ul>
  
  <p>However with the same code, these apps work just fine.</p>
  
  <ul>
  <li>com.hulu.livingroomplus</li>
  <li>com.sling</li>
  <li>com.frogmind.badland</li>
  <li>com.songza.tv</li>
  </ul>
  
  <p>Could anyone provide any insight on what I might be doing wrong?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong>
  I've also tried this and I get the exception </p>
  
  <p>android.content.ActivityNotFoundException: No Activity found to handle Intent { cat=[android.intent.category.LEANBACK_LAUNCHER] flg=0x10000000 pkg=com.netflix.ninja }</p>
  
  <pre><code>public void launchApp(String packageName) {
      Intent intent = new Intent();
      intent.setPackage(packageName);
      intent.addCategory("android.intent.category.LEANBACK_LAUNCHER");
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(intent);
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>This is the code that works for me:</p>
  
  <pre><code>public void launchApp(String packageName) {
      Intent intent = new Intent();
      intent.setPackage(packageName);
  
      PackageManager pm = getPackageManager();
      List&lt;ResolveInfo&gt; resolveInfos = pm.queryIntentActivities(intent, 0);
      Collections.sort(resolveInfos, new ResolveInfo.DisplayNameComparator(pm));
  
      if(resolveInfos.size() &gt; 0) {
          ResolveInfo launchable = resolveInfos.get(0);
          ActivityInfo activity = launchable.activityInfo;
          ComponentName name=new ComponentName(activity.applicationInfo.packageName,
                  activity.name);
          Intent i=new Intent(Intent.ACTION_MAIN);
  
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                  Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
          i.setComponent(name);
  
          startActivity(i);
      }
  }
  </code></pre>