Skip to content

Instantly share code, notes, and snippets.

@Ahmedbadereldin
Last active August 6, 2019 09:04
Show Gist options
  • Save Ahmedbadereldin/7d567f503044c4a241f0a70dca060354 to your computer and use it in GitHub Desktop.
Save Ahmedbadereldin/7d567f503044c4a241f0a70dca060354 to your computer and use it in GitHub Desktop.
this code open whatsapp to send message direct from your app to whatsapp (^_^)
String number = "+970598074212"
/////////////////////////////////////////////////////////////
btn_send_message_whatsapp.setOnClickListener(v -> {
onClickWhatsApp("970598074212");// hint without +
// if the number with + like +970598074212
//using
//onClickWhatsApp(number.substring(1));
});
///////////////////////Open Whatsapp////////////////////////
private void onClickWhatsApp(String phone) {
try {
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(phone) + "@s.whatsapp.net");
startActivity(sendIntent);
} catch (Exception e) {
Toast.makeText(activity, getString(R.string.whatsapp_not_install), Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment