Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open conversation in Whatsapp and populate the text

I want to open WhatsApp to a specific conversation and populate the text field with some string.

Code that I have and I managed to open the conversation with a contact:

private void openConversationWithWhatsapp(String e164PhoneNumber){
    String whatsappId = e164PhoneNumber+"@s.whatsapp.net";
    Uri uri = Uri.parse("smsto:" + whatsappId);
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.setPackage("com.whatsapp");

    intent.putExtra(Intent.EXTRA_TEXT, "text");
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    intent.putExtra(Intent.EXTRA_TITLE, "title");
    intent.putExtra(Intent.EXTRA_EMAIL, "email");
    intent.putExtra("sms_body", "The text goes here");
    intent.putExtra("text","asd");
    intent.putExtra("body","body");
    intent.putExtra("subject","subjhect");

    startActivity(intent);
}

The text box however is not filled with content. I tried to peek inside the AndroidManifest.xml file and found the following info regarding their conversation activity:

<activity android:theme="@style/Theme.App.CondensedActionBar" android:name="com.whatsapp.Conversation" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="stateUnchanged">
    <intent-filter>
        <action android:name="android.intent.action.SENDTO" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="sms" />
        <data android:scheme="smsto" />
    </intent-filter>
</activity>

Does somebody know the extra to use? Are they blocking this on purpose? I saw an API for iOS that they have in their FAQ page.

like image 508
Bogdan M. Avatar asked Jun 04 '14 09:06

Bogdan M.


People also ask

What is WA me in WhatsApp?

138 successfully recognizes the wa.me shortlink: it means the chat will be automatically opened without using the browser. If you want to use wa.me and you have an old WhatsApp version installed, you will be redirected to api.whatsapp.com in your browser," notes the WaBetaInfo report.

How do I open wa me on WhatsApp?

Use https://wa.me/<number> where the <number> is a full phone number in international format. Omit any zeroes, brackets, or dashes when adding the phone number in international format.

What is the use of WA ME /+ 91?

Users need to type https://wa.me/(phone number) of the person they want to drop the text to. They will automatically be directed to the chat. Example if your friends or family members phone number is +91-9876543210 then type https://wa.me/919876543210.

How do you click to chat?

The click-to-chat link allows businesses to chat with customers and website visitors on WhatsApp. Once a person clicks on the link, a chat window will open on their phone or on WhatsApp web, where they can directly chat with the business.


2 Answers

Update in 2017

based on this Whatsapp FAQ

im using this url

https://api.whatsapp.com/send?phone=62xxxxxxx&text=Hello,%20from%20my%20Apps

which 62 is Indonesia's Dialing code

then i use intent like this (im using kotlin)

val uri = Uri.parse("https://api.whatsapp.com/send?phone=62xxxxxxx&text=Hello,%20from%20my%20Apps")
        val intent = Intent(Intent.ACTION_VIEW, uri)
        startActivity(intent)

replace 62xxxxx with your number this work fine to me

like image 81
Ekky Hermestian IW Avatar answered Sep 26 '22 01:09

Ekky Hermestian IW


Try using the following solution to send image and text.

You can setType as "text" and remove extra_stream to use it only for sending text.

            Intent sendIntent = new Intent("android.intent.action.SEND");
            File f=new File("path to the file");
            Uri uri = Uri.fromFile(f);
            sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker"));
            sendIntent.setType("image");
            sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
            sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("919xxxxxxxxx")+"@s.whatsapp.net");
            sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image");
            startActivity(sendIntent);

EXTRA INFORMATION ABOUT THE PROCESS OF FINDING THE SOLUTION :

After reverse engineering WhatsApp, I came across the following snippet of Android manifest,

Normal Share intent, uses "SEND" which does not allow you to send to a specific contact and requires a contact picker.

The specific contact is picked up by Conversation class and uses "SEND_TO" action, but it uses sms body and can not take up image and other attachments.

 <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:name="com.whatsapp.Conversation" android:theme="@style/Theme.App.CondensedActionBar" android:windowSoftInputMode="stateUnchanged">
            <intent-filter>
                <action android:name="android.intent.action.SENDTO"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="sms"/>
                <data android:scheme="smsto"/>
            </intent-filter>
        </activity>

Digging further, I came across this,

 <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:name="com.whatsapp.ContactPicker" android:theme="@style/Theme.App.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.PICK"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="com.whatsapp"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="audio/*"/>
                <data android:mimeType="video/*"/>
                <data android:mimeType="image/*"/>
                <data android:mimeType="text/plain"/>
                <data android:mimeType="text/x-vcard"/>
                <data android:mimeType="application/pdf"/>
                <data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
                <data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
                <data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
                <data android:mimeType="application/msword"/>
                <data android:mimeType="application/vnd.ms-excel"/>
                <data android:mimeType="application/vnd.ms-powerpoint"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND_MULTIPLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="audio/*"/>
                <data android:mimeType="video/*"/>
                <data android:mimeType="image/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:host="send" android:scheme="whatsapp"/>
            </intent-filter>
            <meta-data android:name="android.service.chooser.chooser_target_service" android:value=".ContactChooserTargetService"/>
        </activity>

Finally using a decompiler for ContactPicker and Conversation class,the extra key-value for phone number was found to be "jid".

like image 23
Bhavita Lalwani Avatar answered Sep 25 '22 01:09

Bhavita Lalwani