Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think the answer is a mix of your question and this answer here: <a href="https://stackoverflow.com/a/15931345/734687">https://stackoverflow.com/a/15931345/734687</a> So I would try the following code:</p> <ol> <li>change ACTION_VIEW to ACTION_SENDTO</li> <li>set the Uri as you did</li> <li>set the package to whatsapp</li> </ol> <pre class="lang-java prettyprint-override"><code>Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/" + c.getString(0))); i.setType("text/plain"); i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser i.putExtra(Intent.EXTRA_SUBJECT, "Subject"); i.putExtra(Intent.EXTRA_TEXT, "I'm the body."); startActivity(i); </code></pre> <p>I looked into the Whatsapp manifest and saw that ACTION_SEND is registered to the activity <code>ContactPicker</code>, so that will not help you. However ACTION_SENDTO is registered to the activity <code>com.whatsapp.Conversation</code> which sounds more adequate for your problem.</p> <p>Whatsapp can work as a replacement for sending SMS, so it should work like SMS. When you do not specify the desired application (via <code>setPackage</code>) Android displays the application picker. Thererfor you should just look at the code for sending SMS via intent and then provide the additional package information.</p> <pre class="lang-java prettyprint-override"><code>Uri uri = Uri.parse("smsto:" + smsNumber); Intent i = new Intent(Intent.ACTION_SENDTO, uri); i.putExtra("sms_body", smsText); i.setPackage("com.whatsapp"); startActivity(i); </code></pre> <p>First try just to replace the intent <code>ACTION_SEND</code> to <code>ACTION_SENDTO</code> . If this does not work than provide the additional extra <code>sms_body</code>. If this does not work than try to change the uri.</p> <p><strong>Update</strong> I tried to solve this myself and was not able to find a solution. Whatsapp is opening the chat history, but doesn't take the text and send it. It seems that this functionality is just not implemented. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload