在Whatsapp中打开对话并填充文本 [英] Open conversation in Whatsapp and populate the text
问题描述
我想打开 WhatsApp
进行特定对话,并用一些字符串填充文本字段.
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);
}
但是该文本框未填充内容.我试图窥视 AndroidManifest.xml
文件,发现有关其对话活动的以下信息:
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>
有人知道额外使用吗?他们是故意阻止此行为吗?我在他们的常见问题解答页面中看到了iOS的API.
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.
推荐答案
2017年更新
基于此 Whatsapp常见问题解答
我使用此网址
https://api.whatsapp.com/send?phone=62xxxxxxx&text=Hello,%20from%20my%20Apps
其中62是印度尼西亚的拨号代码
which 62 is Indonesia's Dialing code
然后我使用这样的意图(我使用Kotlin)
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)
用您的电话号码替换62xxxxx这项工作对我来说很好
replace 62xxxxx with your number this work fine to me
这篇关于在Whatsapp中打开对话并填充文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!