Java – how do I send messages from my android app to specific contacts via WhatsApp?

I'm developing an Android application. I need to send messages to specific contacts of WhatsApp. I've tried this Code:

Uri mUri = Uri.parse("smsto:+999999999");
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
mIntent.putExtra("sms_body", "The text goes here");
mIntent.putExtra("chat",true);
startActivity(mIntent);

The problem is that although the contact is selected, the parameter "sms_body" is not received on WhatsApp

resolvent:

Try using intent.extra_ Text instead of SMS_ Body as an additional key. According to WhatsApp's documentation, this is what you must use

An example of their website:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

Their example uses intent. Action_ Send instead of intent.action_ SendTo, so I'm not sure whether WhatsApp supports sending directly to contacts through the intention system. Some quick tests should let you determine

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>