我想打开 WhatsApp
进行特定对话,并用一些字符串填充文本字段。
我拥有的代码,我设法打开了与联系人的对话:
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
文件,发现了以下关于他们对话 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>
有人知道额外的使用方法吗? 他们是故意阻止的吗? 我在他们的 FAQ 中看到了一个适用于 iOS 的 API页面。
最佳答案
2017年更新
基于此Whatsapp FAQ
我正在使用这个 url
https://api.whatsapp.com/send?phone=62xxxxxxx&text=Hello,%20from%20my%20Apps
哪个62是印度尼西亚的区号
然后我使用这样的 Intent (我使用 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 这对我来说很好
关于android - 在 Whatsapp 中打开对话并填充文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24033166/