i want to open whatsapp chat box for some number which is not saved in user mobile.
I am using below code :
Uri uri = Uri.parse("smsto:" + str_MobileNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", "Hello");
i.setPackage("com.whatsapp");
mContext.startActivity(i);
But whatsapp is showing error :
Here's how to do it: Open a browser on your phone or desktop and type the link: https://wa.me/cccxxxxxxxxxx in the address bar. Replace “ccc” with the country code of the recipient (which is a must) and “xxxxxxxxxx” with their phone number.
Users can chat with someone on WhatsApp without saving them as a contact by making use of WhatsApp's click to chat feature via an internet browser. WhatsApp is one of the most popular messaging services in the world and is used by millions of people. The app allows us to connect with people from around the globe.
If you quickly want to send a message to an unknown number, you just have to type the number on your phone's keypad along with the country code and the plus sign before it, like, +911234567890. After typing the number, select it on the keypad itself.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With