Basem Abdelfattah
Basem Abdelfattah

Reputation: 189

Android share intent. Whats App doesnt show up in the picker

i want to enable the users of my app to share a text through whatsapp. I used the description on the whatsapp site:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

The problem, is that the system picker doesnt show whatsapp as an option, although its installed.

Is shareing with the share intent of android not possible anymore?

Thanks for your help

Upvotes: 0

Views: 1240

Answers (2)

Santhosh
Santhosh

Reputation: 3991

In line 5, replace by this, it should work now

startActivity(Intent.createChooser(sendIntent, "Share text via.."));

The chooser allows the user to pick another application instead of default.

Upvotes: 3

Try this :

PackageManager pm=getPackageManager();
    try {

        Intent waIntent = new Intent(Intent.ACTION_SEND);
        waIntent.setType("text/plain");
        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.setPackage("com.whatsapp");

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

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

Upvotes: 1

Related Questions