Sending a text intent using Anko
Anko provides a wrapper around the intent actions, which makes calling actions super easy. One of those actions is sending an SMS. In this recipe, we will see how to launch an intent that sends messages to a telephone number.
Getting ready
I'll be using Android Studio for coding purposes. You need to include Anko library in your build.gradle
file. Just add the given lines and you are good to go:
compile "org.jetbrains.anko:anko-commons:$anko_version"
You can also clone the gitlab.com/aanandshekharroy/Anko-examples repository and switch to the 3-intent-actions
branch to get the source code.
How to do it…
Let's follow these steps to send an SMS using intents:
- Anko provides the
sendSMS
method, which takes in two parameters—one of them is the phone number, and the other is the message:
sendSMS("+9195XXXXXX","Hi")
- Calling this method will launch the messaging app, or will ask you which messaging app to launch if you have more than one type of that app and will prefill...