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?
If the user does not have the Whatsapp app in their device then the user will get the ActivityNotFoundException
Then, you should move the user to download the app first.
public void shareViaWhatsApp() {
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Application of social rating share with your friend");
try {
Objects.requireNonNull(getActivity()).startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.whatsapp")));
}
}