How to use messaging in android application by using WhatsApp and WeChat?
Actually requirement is to send sms using WhatsApp and We
you can try one of these two solutions they worked for me.
reference: https://faq.whatsapp.com/en/android/26000030/?category=5245251
private void openWhatsApp(String countryCode, String mobile) {
String customerPhoneNumber = String.format("%s%s", countryCode, mobile);
Uri uri = Uri.parse("smsto:" + customerPhoneNumber);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
sendIntent.setPackage("com.whatsapp");
if(sendIntent.resolveActivity(getPackageManager()) == null){
showDialogMessage("you should install whatsapp.");
return;
}
startActivity(sendIntent);
}
or
private void openWhatsApp(String countryCode, String mobile) {
String customerPhoneNumber = String.format("%s%s", countryCode, mobile);
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setPackage("com.whatsapp");
// you can remove this part ("&text=" + "your message")
String url = "https://api.whatsapp.com/send?phone=" + customerPhoneNumber + "&text=" + "your message";
sendIntent.setData(Uri.parse(url));
if(sendIntent.resolveActivity(getPackageManager()) == null){
showDialogMessage("you should install whatsapp.");
return;
}
startActivity(sendIntent);
}