I'm using this code in order to send a message to a specific number in WhatsApp:
public void sendMessage() {
runOnUiThread(new Runnable() {
@Override
public void run() {
String whatsappid = "962795195996@s.whatsapp.net";
Cursor c = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Contacts.Data._ID },
ContactsContract.Data.DATA1 + "=?",
new String[] { whatsappid }, null);
c.moveToFirst();
Intent whatsapp = new Intent(Intent.ACTION_VIEW,
Uri.parse("content://com.android.contacts/data/"
+ c.getString(0)));
c.close();
whatsapp.putExtra(Intent.EXTRA_TEXT, "Test...");
whatsapp.setPackage("com.whatsapp");
try {
startActivity(whatsapp);
} catch (android.content.ActivityNotFoundException ex) {
ex.printStackTrace();
}
}
});
}
When running the code, WhatsApp is opened on the message history with that number but the text message is not filled in the input box. How can this be solved?