I'm developing an app, and I want to send a WhatsApp message to a specific number
I used this code from Satheesh's answer here and make corrections.
but the users who installed both WhatsApp messenger and business WhatsApp, this code send a message into business WhatsApp directly, it didn't show options to allow the users to choose between two apps
in android 5 it shows options but android 7 and 8 it didn't show options. it sends to business WhatsApp only.
can you help me to allow to give options to choose between both apps in android 7 and 8?
private void openWhatsApp (String phoneNumber) {
boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
if (isWhatsappInstalled) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://api.whatsapp.com/send?phone="+phoneNumber));
startActivity(intent);
} else {
Uri uri = Uri.parse("market://details?id=com.whatsapp");
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
Toast.makeText(getActivity(), "WhatsApp not Installed",
Toast.LENGTH_SHORT).show();
startActivity(goToMarket);
}
}
private boolean whatsappInstalledOrNot(String uri) {
PackageManager pm = getActivity().getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}