Created
February 9, 2021 10:56
-
-
Save pasmat/45bdfbe2e52aa838fe86f21f251cc39d to your computer and use it in GitHub Desktop.
Open E-mail intent Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun tryVerifyMail() { | |
try { | |
val intents: List<Intent> = (packageManager.queryIntentActivities(Intent( | |
Intent.ACTION_SENDTO, Uri.fromParts( | |
"mailto", "[email protected]", null | |
) | |
), 0) + packageManager.queryIntentActivities(Intent(Intent.ACTION_VIEW).also { | |
it.type = "message/rfc822" | |
}, 0)).mapNotNull { | |
it.activityInfo.packageName | |
}.toSet().mapNotNull { | |
packageManager.getLaunchIntentForPackage(it) | |
} | |
if(intents.size > 0) { | |
startActivityForResult(Intent.createChooser(intents.first(), getString(R.string.verify_mail)).also { | |
if(intents.size > 1) { | |
it.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.subList(1, intents.size - 1).toTypedArray()) | |
} | |
}, OPEN_MAIL_REQUEST_CODE) | |
} else { | |
Toast.makeText(this, "Verify your e-mail by clicking the link in your e-mail inbox.", Toast.LENGTH_LONG).show() | |
} | |
} catch (e: ActivityNotFoundException) { | |
// Show error message | |
e.printStackTrace() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment