Whatsapp is something which doesn’t require any introduction. It’s a conversation app used by millions of users across the world. These million users make it unique for developers also to give special attention when it comes to sharing some message through Whatsapp.
During recent times, I was asked multiple times in the comments section or even emails, if there is any possible way where we can send the text message directly to a WhatsApp contact?
This post was originally posted at https://agrawalsuneet.github.io/blogs/android-share-message-directly-to-whatsapp-contact/ and reposted on Medium on 23rd Oct 2020.
The ideal way any app accepts text, image, video or any other format for sharing is through intent filters defined in the manifest file.
Whatsapp also does the same and accepts all possible format (with some size and other limitations) but that will take you to a contact selection screen in Whatsapp.
If you want to share the text directly to a contact on WhatsApp, there is a hack which is actually not documented anywhere but using the same we can achieve it.
There is an API from WhatsApp which accepts phone and
query parameters and if you call that API, it actually opens WhatsApp, check if that number exists on WhatsApp, if yes it opens conversation with that number and paste the message. If the contact or mobile numbers doesn’t exist on WhatsApp, it shows a popup saying contact doesn’t exist on WhatsApp.