title: Get And Display List Of Installed Programs on Android
body: <p>I'm currently developing an app that will allow the user to choose an app and launch it at a later time (there is more functionality but this is the main thing I'm having an issue with.)</p>
  
  <p>I'm looking for a way to get a list of the applications (user installed or updateable ex. Gmail, GMaps, etc...) And throw it into an AlertDialog similar to how you add a shortcut to the Homescreen (Long press -> Applications).</p>
  
  <p><a href="https://stackoverflow.com/questions/6165023/get-list-of-installed-android-applications">This</a> is the thread I'm using that has the code to get the list of applications that I need. However how would I turn this into an AlertDialog?</p>
  
  <p>Here is the code from the thread.</p>
  
  <pre><code>public void getApps()
  {
      PackageManager pm = getPackageManager();
      List&lt;ApplicationInfo&gt; apps = pm.getInstalledApplications(0);
      List&lt;ApplicationInfo&gt; installedApps = new ArrayList&lt;ApplicationInfo&gt;();
  
      for(ApplicationInfo app : apps) {
          //checks for flags; if flagged, check if updated system app
          if((app.flags &amp; ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
              installedApps.add(app);
          //it's a system app, not interested
          } else if ((app.flags &amp; ApplicationInfo.FLAG_SYSTEM) == 1) {
              //Discard this one
          //in this case, it should be a user-installed app
          } else {
              installedApps.add(app);
          }
      }
  }//end getApps()
  </code></pre>
  
  <p>And here is the code I use for displaying an AlertDialog similar to what I want to use. </p>
  
  <pre><code>//PseudoCode does not compile
  public void displayAppList(View v)
  {
      final CharSequence[] items = {getApps()};
  
      AlertDialog.Builder builder = new AlertDialog.Builder(SchedulerActivity.this);
      builder.setTitle("Choose an App To Launch");
      builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
              appChoiceString[count] = items[item];
       Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
          }
      });
  
      builder.setPositiveButton("Yes",
       new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
         Toast.makeText(SchedulerActivity.this, "Success", Toast.LENGTH_SHORT).show();
        }
       });
      builder.setNegativeButton("No",
       new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
         Toast.makeText(SchedulerActivity.this, "Fail", Toast.LENGTH_SHORT).show();
        }
       });
      AlertDialog alert = builder.create();
      alert.show();
  }
  </code></pre>
  
  <p>Any help as to getting this to display properly would be awesome.</p>