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(); } }
source share