Using Android Intent system we can share on whats app from our application. Whats App application have listeners that listen to intents to share media and texts.
Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:
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);
However, if you want to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent:
sendIntent.setPackage("com.whatsapp");
This would simply be set right before you call startActivity(sendIntent);
Note:- Make sure that you have whats app installed in your device before calling the above Intent
0 Comment(s)