1

Is there a way to know if the user has chosen the intent action from the chooser or not.

I want to do this - If its chosen by user then finish the current activity else remain in the current activity.

I have this code:

startActivity(Intent.createChooser(email, "Choose an Email client :"));
finish();

But this always finishes the current activity irrespective of user chose the email client or not.

Any ideas?

sjain
  • 23,126
  • 28
  • 107
  • 185

1 Answers1

4

You can do this by showing you own custom chooser

First get all packages which can process your intent

private List<String> getInstalledComponentList(Intent emailIntent)
            throws NameNotFoundException {

        List<ResolveInfo> ril = getPackageManager().queryIntentActivities(emailIntent, 0);
        List<String> componentList = new ArrayList<String>();
        String name = null;

        for (ResolveInfo ri : ril) {
            if (ri.activityInfo != null) {
                Resources res = getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo);
                if (ri.activityInfo.labelRes != 0) {
                    name = res.getString(ri.activityInfo.labelRes);
                } else {
                    name = ri.activityInfo.applicationInfo.loadLabel(
                            getPackageManager()).toString();
                }
                componentList.add(name);
            }
        }
        return componentList;
    } 

Then show a dialog with all this list of packages like this

Then process the click event and start the selected package

Arun C
  • 9,035
  • 2
  • 28
  • 42