简体   繁体   English

向WhatsApp联系人发送消息

[英]Sending message to whatsapp contacts

I recently tried the code to send message to whatsapp using intent. 我最近尝试了使用意图将代码发送消息到whatsapp的代码。 But i was wondering if there's any way to directly send the message with the intent action rather than having the text typed in the message box of that contact once a contact is selected. 但是我想知道是否有任何方法可以通过意图操作直接发送消息,而不是一旦选择了某个联系人,便在该联系人的消息框中键入文本。 I want the text to be sent to the contact once i select it. 我希望将文本选择后发送给联系人。

Whats app provide 2 methods to send messages: Whats应用程序提供2种发送消息的方法:

  1. Custom URL Scheme 自定义网址方案
  2. Android intent system Android意图系统

Custom URL Scheme 自定义网址方案

Opening whatsapp://send?text= followed by the text to send, will open WhatsApp, allow the user to choose a contact, and pre-fill the input field with the specified text. 打开whatsapp:// send?text =,后跟要发送的文本,将打开WhatsApp,允许用户选择联系人,并用指定的文本预填充输入字段。

Eg: 例如:

 <a href="whatsapp://send?text=Hello%20World!">Hello, world!</a> 

Android intent system Android意图系统

Like most social apps on Android, WhatsApp listens to intents to share media and text. 与Android上的大多数社交应用程序一样,WhatsApp会听取共享媒体和文本的意图。 Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker: 例如,只需创建一个共享文本的意图,系统选择器就会显示WhatsApp:

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);

More information can be found on WhatsApp Faq and on Android developer documentation . 可以在WhatsApp常见问题解答Android开发人员文档中找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM