android - 在 Whatsapp 中打开对话并填充文本

标签 android whatsapp

我想打开 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/

相关文章:

android 如何包装微调器下拉文本 (android 4)

android - 使用 OpenCV 3.1 在 Android Studio 1.5 中开发原生 C++ 应用程序

javascript - Whatsapp 按钮在 Android 上工作但在 IOS 上空白

php - 在 WhatsApp 消息中创建换行符

android - 在后台发送 WhatsApp 消息或发送消息并在 android 中关闭应用程序

html - 如何在网站上的 WhatsApp 共享段落后添加中断?

android - android布局xml中的background、backgroundTint、backgroundTintMode属性有什么区别?

java - ScrollView 不是从顶部开始

java - 删除 View 的子级然后读取它后, View 将无法正常显示

IOS应用程序复制