Send a message to a user on WhatsApp from my application (Android)

I read a lot of WhatsApp posts here on StackOverflow.

Like these: Is it legal to use WhatsAPI?

Android Whatsapp / Chat Examples

Sending a message through WhatsApp

My question is that. I managed to send a message from my application to WhatsApp for those in my contact list.

However, I want to send a message (NOT SPAM!) To someone who is not in my contact list through WhatsApp, and I cannot do this with these solutions.

How is this possible?

By the way, how can I fill out the body of a WhatsApp text box with a predefined message so that the user can immediately edit or send? "sms_body" or Intent.EXTRA_TEXT doesn't seem to work ...

public void shareWhatsApp(String whatsappid) { try { Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?", new String[] { whatsappid }, null); c.moveToFirst(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0))); i.putExtra(Intent.EXTRA_TEXT, "Hello!"); startActivity(i); c.close(); } catch (Exception e) { Toast.makeText(this, "Install WhatsApp First", Toast.LENGTH_LONG).show();; e.printStackTrace(); } } 
+6
source share
2 answers

You will need some EXTRAS to be included in the intent. You can also use a phone number instead of an identifier.

Check out this solution here.

0
source

I recently answered this question and it works very well, please find my answer here:

Send text for a specific contact programmatically (whatsapp)

Indeed, to send a specific message to WhatsApp from your own Android application, you really need to send a specific message,

Enjoy! :)

0
source

Source: https://habr.com/ru/post/972324/


All Articles