Last active
October 10, 2023 16:37
-
-
Save hetang/fccd04ffed62875bd70de0a43b980a8d to your computer and use it in GitHub Desktop.
Open Email inbox or compose view in Android
This file contains 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
/** | |
* This function open email compose view and post HTML body | |
**/ | |
// val body = Html.fromHtml(fragment.resources.getString(R.string.email_body)) | |
fun navToEmailCompose(email: String, subject: String, body: String) { | |
val intent = Intent(Intent.ACTION_SENDTO, | |
Uri.parse("mailto:${email}")) | |
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject) | |
intent.putExtra(android.content.Intent.EXTRA_TEXT, body) | |
startActivity(Intent.createChooser(intent, "Email")) | |
} | |
/** | |
* This function open default email inbox view | |
**/ | |
fun navToEmail() { | |
val intent = Intent(Intent.ACTION_MAIN) | |
intent.addCategory(Intent.CATEGORY_APP_EMAIL) | |
startActivity(intent) | |
} | |
/** | |
* This function open email app chooser to open inbox view | |
**/ | |
fun navToEmail() { | |
val intent = Intent(Intent.ACTION_MAIN) | |
intent.addCategory(Intent.CATEGORY_APP_EMAIL) | |
startActivity(Intent.createChooser(intent, "Email")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your gist, but navToEmail does not work properly since most of the app out there does not use CATEGORY_APP_EMAIL unfortunately (except gmail). I did find a workaround on stackoverflow and create a kotlin version of https://stackoverflow.com/a/69043615/3289338 that also work on Android > 11