Last active
August 6, 2019 09:04
-
-
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 (^_^)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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