January 2018
Intermediate to advanced
434 pages
14h 1m
English
Let's take a look at its implementation:
fun Context.email(email: String, subject: String = "", text: String = ""): Boolean { val intent = Intent(Intent.ACTION_SENDTO) intent.data = Uri.parse("mailto:") intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(email)) if (subject.isNotEmpty()) intent.putExtra(Intent.EXTRA_SUBJECT, subject) if (text.isNotEmpty()) intent.putExtra(Intent.EXTRA_TEXT, text) if (intent.resolveActivity(packageManager) != null) { startActivity(intent) return true } return false}
As you can see, it checks for the extra data, such as the subject and message body, and then launches the email application. The email function provided by Anko is just a convenient method that reduces your line of code and makes your code ...
Read now
Unlock full access