VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-send-message-on-whatsapp-in-android/

⇱ How to send message on WhatsApp in Android - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to send message on WhatsApp in Android

Last Updated : 15 Jul, 2025

Whatsapp is the one of most popular messaging App. Many android applications need the functionality to share some messages directly from their app to WhatsApp. For example, if a user wants to share the app or share a message from the app then this functionality comes in use. Either user can send a text or a predefined text can also be sent through this. This article demonstrates how an android application can send messages on WhatsApp. Whatsapp must be installed on the user's device.

Approach

Step 1:Open the activity_main.xml file and add the layout code. A message input container as EditText and a Button to send this message is added.

Step 2: Take the reference of EditText and Button in Java file. References are taken using the ids with the help of findViewById() method.

  • Taking reference to EditText
    EditText messageEditText = findViewById(R.id.message);
  • Taking reference to Button
    Button submit = findViewById(R.id.submit);

Step 3: Write function to send message to whatsapp. Create an intent with ACTION_SEND and specify the whatsapp package name to this so that it opens whatsapp directly.

com.whatsapp is the package name for official whatsapp application.

Step 4: Set onClickListener to the button. It takes the text entered by the user and calls the function sendMessage in which the text message is sent as a parameter.

Below is the complete MainActivity.java file:

Output:

Comment
Article Tags:
Article Tags:

Explore