0

I would like to be able to have the ability for users to be able to set up a predefined email, which is stored and then sent later based upon some trigger. The stumbling block here is that I want the user to be able to choose what app they use for this. Simply calling Intent.createChooser does nothing on its own, the app is not selected until startActivity() is called on it, which then opens the selected app. The problem here is, since I want to send the email later, either the app chooser is not triggered until the email is (which may be while the screen is off), or the app chooser is triggered at setup-time, which will then leave my app, interrupting setup, when an app is selected in the chooser.

Is there some way to have a createChooser-style menu open, allowing the user to select one of the apps available for association with a certain intent, but then merely return the name of that app to my app, so that its information can be stored for creating and executing later intents?

biotinker
  • 51
  • 1
  • 4
  • 5
    Create your own [chooser](http://stackoverflow.com/questions/19298048/android-custom-intent-chooser), and save the relevant info for whichever one the user selects. – Mike M. Apr 24 '16 at 06:54
  • This was a bit of a pain to get working, but ultimately it seems to be what I want. Thanks! – biotinker Apr 25 '16 at 04:18

1 Answers1

0

You can do this:

PackageManager packageManager = getPackageManager();
List<String> results = new ArrayList<String>();
Intent intent = new Intent(YourAction); //Put any action string you have in mind
//Or any Intent intent = new Intent(...) you think fits

List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
for (ResolveInfo resolveInfo : activities) {
    ActivityInfo activityInfo = resolveInfo.activityInfo;
    if (activityInfo != null) {
        results.add(activityInfo.name);
    }
}

results will hold the activity names that can perform the action you need.

Pooya
  • 6,083
  • 3
  • 23
  • 43