3

I see many posts about whatapp intents, but cannot find a working answer for this question;

I want an intent for Whatsapp to send a message to a given number. This number won't change. I need no message to be there. However, I need a working example even if this number isn't in the contacts of the device.

It seems that this is not possible, but is there a way to add a contact programmatically?

Thanks

RJB
  • 1,704
  • 23
  • 50
  • This is not possible right now. Whatsapp just open chat history page using intent.There is no another way for it.Please refer below link for information https://www.whatsapp.com/faq/android/28000012 http://stackoverflow.com/questions/19081654/send-text-to-specific-contact-whatsapp – iAndroid Jul 20 '16 at 11:29

1 Answers1

3

Sorry for late reply. I suppose your problem must be solved by now. You can try following code to open conversation for not saved numbers:

private void openWhatsApp(String number) {
        try {
            number = number.replace(" ", "").replace("+", "");

            Intent sendIntent = new Intent("android.intent.action.MAIN");
            sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
            sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(number)+"@s.whatsapp.net");
            context.startActivity(sendIntent);

        } catch(Exception e) {
            Log.e(TAG, "ERROR_OPEN_MESSANGER"+e.toString());
        }
    }
Sanju
  • 663
  • 9
  • 20