Open the E-Mail client on button click

from the CommonsWare Community archives

At March 15, 2021, 5:49pm, Raptor asked:

Hello,

I am looking for a way to open any available email client at the press of a button. I know you can do that to send an email with an intent, but in my case the situation is for receiving an email (the user just registered and the app wants to open his or her email client so they can validate a registration link).

Is there any way to just give the user the ability to open their email client without any additional “send email” action?

Thanks!


At March 24, 2021, 10:36am, mmurphy replied:

My sincere apologies in the delay in responding! Something appears to have gone haywire, where I am not getting emails from my own discussion board.

That plan seems like it may have issues:

Not reliably. Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_EMAIL) is what you want — use that Intent to start an activity. However, in addition to the above problems, there is no requirement for the user’s email app to be advertising that it is part of CATEGORY_APP_EMAIL. So, make sure you wrap your startActivity() call in a try/catch block, and handle the ActivityNotFoundException.


At March 24, 2021, 12:38pm, Raptor replied:

I know, I am aware of these issues, but they don’t seem to be. Oh well, I can’t do the project management too, right? If that’s what they want, that’s what I’m going to give them, but yes, it’s a bad idea.

I will try as you suggested, thanks!