Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send message to user in WhatsApp from my app (Android)

I've gone through plenty of WhatsApp posts here in StackOverflow.

Like these: Is it legal to use WhatsAPI?

Android Whatsapp/Chat Examples

Sending message through WhatsApp

My question is this. I manage to send a message from my app to WhatsApp for someone that is in my contact list.

However, I want to send a message (NOT SPAM!) to someone who is not on my Contact List through WhatsApp, and I'm unable to do so with the given solutions.

How is it possible?

By the way, how is it possible to fill the body of a WhatsApp text field with a pre-defined message, so the user can edit or send immediately? "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();
    }
}
like image 928
Ori Frish Avatar asked Jul 16 '14 13:07

Ori Frish


1 Answers

You should only access Call Log or SMS permissions when your app falls within permitted uses and only to enable your app’s critical core functionality.

Core functionality is defined as the main purpose of the app. This may comprise of a set of core features, which must all be prominently documented and promoted in the app's description. Without the core feature(s), the app is "broken" or rendered unusable. link -https://support.google.com/googleplay/android-developer/answer/9047303?source=post_page-----9b8226de7827----------------------

like image 57
Nikhil Vaish Avatar answered Oct 11 '22 12:10

Nikhil Vaish