Send WhatsApp Messages using the Android SDK

Prabhakar Thota
2 min readMay 30, 2022

--

Learn how to use this Android SDK to Send WhatsApp Messages using the WhatsApp API

Before jumping into using the SDK, let’s follow the below steps to create the project on developers.facebook.com to claim the phone number id.

Step 1: Create a WhatsApp App

Give your app a descriptive name (do not use any Facebook trademarks like WhatsApp or Facebook in the app name) and click the Create App button to create the app.

On the next screen, you will be required to link your WhatsApp app to your Facebook business account. You will also have the option to create a new business account if you don’t have one yet.

Step 2: Add Recipient’s phone number

Your WhatsApp app will provide you with a temporary access token that will be valid for 23 hours. Make a note of this token as we’ll need it in a later step.

Use below Android SDK to Send WhatsApp Messages using the WhatsApp API

Kindly use the following links to use this library:

In settings.gradle (Project)

dependencyResolutionManagement {
repositories {
…….
maven { url ‘https://jitpack.io' }
}
}

And then in the other gradle file(maybe your app gradle or your own module library gradle, but never add in both of them to avoid conflict.)

dependencies {
implementation ‘com.github.myinnos:WhatsApp-SDK:<latest-version>’
}

How to use
— — -
Step 2: implement the App Icon Name Changer method :

Example — MainActivity.kt

WhatsAppInitialization.sendMessage(
“token”, //token
“version”, //ex: v13.0
“phone_number_id”, //ex: 103075932423434
“customer_phone_number”,
“template_name”, //ex: hello_world
“language_code”, //ex: en_US
) { wResult ->
Handler(Looper.getMainLooper()).post {
if (wResult?.getMessage() == null) {
// failed results
} else {
// success results
Log.d(“RESULTS”, wResult.getMessage())
}
}
}

Any Queries? or Feedback, please let me know by opening a new issue

PS: Images in the article are taken from labnol

Let me know your thoughts on Twitter.

--

--

Prabhakar Thota

Mobile Engineer, UI/UX. I believe in the quote, “Creativity is thinking up new things. Innovation is doing new things.” Happy Coding :)