Method 1 - Using android component name
public static void openWhatsAppConversation(Context context, String number, String message) {
number = number.replace(" ", "").replace("+", "");
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(number) + "@s.whatsapp.net");
context.startActivity(sendIntent);
}
Method 2 - Using whatsapp api uri
public static void openWhatsAppConversationUsingUri(Context context, String numberWithCountryCode, String message) {
Uri uri = Uri.parse("https://api.whatsapp.com/send?phone=" + numberWithCountryCode + "&text=" + message);
Intent sendIntent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(sendIntent);
}