android - 通过单击我的应用程序(Kotlin)中的按钮打开与特定联系人的 WhatsApp 聊天
问题描述
如何通过单击我的应用程序中的按钮打开与特定联系人的 Whatsapp 聊天?
这就是我使用的代码。它会打开 WhatsApp 并让我搜索我想向其发送消息的联系人,但它不会打开带有我提供给它的特定联系人号码的 WhatsApp 聊天。
whatsappButton.setOnClickListener{
var con = itemView.context
val textToShare = "*כח אדם*"
val phoneNumber = blogPost.phone
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.type = "text/plain"
sendIntent.putExtra("jid", phoneNumber+"@s.whatsapp.net")
sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare)
val extra = sendIntent.extras
startActivity(con,sendIntent,extra)
}
解决方案
请在此处检查此答案 使用以下代码:
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.setType("text/plain");
i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);
推荐阅读
- google-bigquery - 从配置文件中寻找 BQ SQL builder
- node.js - 赛普拉斯 UI 测试因等待浏览器而超时
- unity3d - 在 Unity 中为对象的不同部分分配不同颜色的着色器
- php - 如何将多个数组项与一个数组项进行比较以进行猜词脚本
- mysql - 如何仅对特定行的值求和?
- systemc - 端口未绑定 SystemC (E112)
- css - 移动设备和桌面设备不会返回卡背面的左箭头
- symfony - 检查网络服务器是否正在运行,并且没有防火墙阻止 Facebook 的爬虫 Symfony
- r - 由于压缩文件夹中的名称过长,解压失败
- python - 我在 Python 中遇到问题,我相信 openpyxl