Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

want to open whatsapp to chat with a unsaved contact number in android app

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 : enter image description here

like image 230
BHARAT GUPTA Avatar asked Jul 09 '16 02:07

BHARAT GUPTA


People also ask

How do I message a non Saved number on WhatsApp?

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.

Can you chat with someone not in your contacts on WhatsApp?

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.

How do I text a number without a contact on WhatsApp?

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.


1 Answers

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);
}
like image 67
pvrforpranavvr Avatar answered Oct 04 '22 17:10

pvrforpranavvr