‘Share to WhatsApp’ Code for Android Developers


Most applications provide sharing to WhatsApp using the generic ‘Share’ intent. However, you may want to make the user directly share the content to WhatsApp without showing the App Chooser. Here’s a quick Java snippet for Android developers who want to directly integrate Share on WhatsApp functionality on their Android app. Create a button and set its onClick attribute to the onClickWhatsApp function below.

public void onClickWhatsApp(View view) {

    PackageManager pm=getPackageManager();
    try {

        Intent waIntent = new Intent(Intent.ACTION_SEND);
        String text = "YOUR TEXT HERE";

        PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
        //Check if package exists or not. If not then code 
        //in catch block will be called

        waIntent.putExtra(Intent.EXTRA_TEXT, text);
        startActivity(Intent.createChooser(waIntent, "Share with"));

   } catch (NameNotFoundException e) {
        Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)


If you added Twitter Sharing functionality to your app, you may also want to Add Twitter sharing to your Android application.

As an Android developer, you might also want to check out our free GCM Notifications Test Tool and bookmark How to Recover Lost Android Keystore Password.

Leave us a quick comment or a thank you note if you found the tip to incorporate WhatsApp sharing functionality in your Android application useful.

One thought on “‘Share to WhatsApp’ Code for Android Developers

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge