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.
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:
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- How to send message on WhatsApp in Android using Kotlin
- Android | How to send data from one activity to second activity
- How to send an Email from your Android App?
- How to create popup message using Alerter Library in android
- Sending a Text Message Over the Phone Using SmsManager in Android
- Send email using Java Program
- Android | AdMob Banner Ads for Android Studio
- Android | Android Application File Structure
- Android | AdMob Interstitial Ads for Android Studio
- Android | How to Create/Start a New Project in Android Studio?
- Android | Running your first Android app
- Android | How to add Radio Buttons in an Android Application?
- Android | How to Request permissions in Android Application?
- Difference between Android 1.1 and Android 4.0.1
- Difference between Android 1.1 and Android 2.3.4
- Difference between Android 1.0 and Android 1.1
- Difference between Android 1.0 and Android 7.1
- Difference between Android 1.0 and Android 2.3
- Difference between Android 1.0 and Android 2.2
- Difference between Android 1.0 and Android 1.6
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.