DEV Community

Cover image for Send WhatsApp Messages using the Android SDK
Prabhakar Thota
Prabhakar Thota

Posted on

Send WhatsApp Messages using the Android SDK

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

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

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.

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

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.

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

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' }
    }
}
Enter fullscreen mode Exit fullscreen mode

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>'
}
Enter fullscreen mode Exit fullscreen mode

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())
                    }
                }
            }
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (2)

Collapse
 
pankti_s profile image
Pankti Sidhpura

Hi, I'm Pankti and I work for a Market Research agency called MarketVistas.
For a research, we're looking to speak to a few profiles that might be similar to yours. You shall certainly be reimbursed for your time and effort. Please see below the different profiles we need. Please hit us up if interested!
We promise you, we're legit!

~5 Software developers that develop tools/add-ons for WhatsApp (unofficially, or in a capacity not directly related to Meta/WhatsApp)
~1-2 Software architects or designers that work on development projects on WhatsApp (same scope as above)
~1-2 Other members of a company or development team that work for a company that does specific development for to WhatsApp. Ideally, this would maybe be the CEO of a small development firm with 10-50 employees. Would likely have a lot of development in their own background.

Collapse
 
myinnos profile image
Prabhakar Thota

you can reach out to me on twitter (twitter.com/MyInnos)