0

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.)

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).

This 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?

Here is the code from the thread.

public void getApps()
{
    PackageManager pm = getPackageManager();
    List<ApplicationInfo> apps = pm.getInstalledApplications(0);
    List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();

    for(ApplicationInfo app : apps) {
        //checks for flags; if flagged, check if updated system app
        if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
            installedApps.add(app);
        //it's a system app, not interested
        } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
            //Discard this one
        //in this case, it should be a user-installed app
        } else {
            installedApps.add(app);
        }
    }
}//end getApps()

And here is the code I use for displaying an AlertDialog similar to what I want to use.

//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();
}

Any help as to getting this to display properly would be awesome.

Community
  • 1
  • 1
Cistoran
  • 1,587
  • 15
  • 36
  • 54

1 Answers1

3

Why not just use the standard intent chooser? (See this). Otherwise, you probably want to explain what is not displaying the way you want, and how you really want it to look in detail.

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • I have nothing to display at the moment. I have a List(see above) of all the user installed/updateable apps and I want to figure out a way to put that into an AlertDialog(List with Radio Buttons and an Ok/Cancel button). I've never used Intent and every time I've tried to read the articles it just seems like jibberish to me with no actual example code. – Cistoran Nov 16 '11 at 21:03
  • In order to launch apps, etc. you're going to have to understand intents at some point. It's a fundamental part of how Android apps work. You've probably already seen this, but this doc is probably a good place to start: http://developer.android.com/guide/topics/intents/intents-filters.html – kabuko Nov 16 '11 at 21:35
  • I actually hadn't seen that before. Thanks for the link. – Cistoran Nov 17 '11 at 19:23