Android send user to email client chooser

Viewed 42

I am trying to redirect user to check his email via available email clients. Currently what I have achieved is to send the user directly to Gmail client. Below there are some functions that I use to generate implicit intent:

fun attept1(): Intent {
    val intent = Intent.makeMainSelectorActivity(
        Intent.ACTION_MAIN, 
        Intent.CATEGORY_APP_EMAIL
    )
    intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
    return intent
}

fun attempt2(): Intent {
    val intent = Intent(ACTION_VIEW)
    intent.type = "message/rfc822"
    intent.addFlags(FLAG_ACTIVITY_NEW_TASK)
    return intent
}

//... somewhere in the code

val emailIntent = attempt1() //or attempt2()

startActivity(emailIntent)

With attempt 1 I am successfully redirecting the user to Gmail but I do have at least 5 email clients installed (BlueMail, Outlook, Yahoo Mail, Email, Temp Mail). They're ignored completely.

With attempt 2, at first it was showing unrelated apps like Slack, but after I have installed other email clients it just shows a toast message: Can't open this file. I have tried with Intent.createChooser(intent, "Choose client: ") but it didn't work either.

0 Answers
Related