0

I am trying to send some message to whatsapp using the following code but it gives error android system has stopped but the intent is working fine. and the text is also added in the message. What could be the problem?

PackageManager pm = getPackageManager();
        try {

            Intent waIntent = new Intent(Intent.ACTION_SEND);
            waIntent.setType("text/plain");
            String text =  " http://play.google.com/  ";
            PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
            waIntent.setPackage("com.whatsapp");
            waIntent.putExtra(Intent.EXTRA_TEXT, text);
            startActivity(Intent.createChooser(waIntent, "Share with"));

        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
                    .show();
        }
Saransh Agarwal
  • 305
  • 5
  • 18
  • This [link](http://techbeasts.com/how-to-fix-unfortunately-whatsapp-has-stopped-on-android/) will help you. – Fady Saad Apr 18 '17 at 02:31

1 Answers1

0

Found this answer

Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "share text");
try {
     startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
     Toast.makeText(this, "Whatsapp not installed", Toast.LENGTH_SHORT).show();
}
Community
  • 1
  • 1
Saransh Agarwal
  • 305
  • 5
  • 18