Send WhatsApp Messages using the Android SDK

Send WhatsApp Messages using the Android SDK

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

172007.png

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.

172539 (1).png

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.

173159 (1).png

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

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 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.