0

I have 2 types of Intents for sharing. One for simple generic messaging like SMS/Slack etc. and Another one for email. What I can't seem to figure out is how to make where I can find a way to resolve what someone has chosen via the chooser and use the appropriate intent.

(This would be done via pressing the share button and all send options would show in the chooser

Any help with this would be awesome.

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain"); 
Intent chooser = Intent.createChooser(shareIntent,"");

My thought was when resolving the chooser I could see if it was an email type but that doesn't seem to work either.

HexBlit
  • 1,172
  • 1
  • 13
  • 31

1 Answers1

0

Once you have fired off an Intent, control of what happens is outside your control. The chooser will not provide a callback to your app once the user chooses an action- instead the system will pass the intent you launched on to the selected application.

As discussed in How to filter specific apps for ACTION_SEND intent (and set a different text for each app), if you want to customize the chooser you have a few options. You can:

  • Use Intent.EXTRA_INITIAL_INTENTS to surface other intents in addition to the default option.
  • Create your own custom chooser that provides the behavior you want

The first option may not be ideal because the ordering of options might not be want you want.

The second option provides much more control, but is a lot of work to maintain, particularly if you want newer platform features like directly sharing with a contact.

Another option would be to change your UI to offer separate "share" and "email" options, then use the default intents for each.

Community
  • 1
  • 1
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120