How to share text to WhatsApp from my app?

user1755441 picture user1755441 · Oct 18, 2012 · Viewed 68.4k times · Source

I develop an app with a functionality for sharing text. This is working fine except for WhatsApp. What should I do? Is there any specific API for that?

Answer

Sonny Ng picture Sonny Ng · Sep 3, 2013

You can use intent to do so. No need to use Whatsapp API. Hope that I have not misunderstood your question. Hope that helps, thanks.

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
try {
    activity.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastHelper.MakeShortText("Whatsapp have not been installed.");
}