我在whatsapp应用程序中创建了一个意图,如果我单击电话号码列表,它将打开whatsapp并打开对话(如果该号码存在于whatsapp中)。我成功直到打开对话。让我陷入困境的事情是,我的意图之内没有传达任何讯息。因此,WhatsApp文本框中未显示任何内容。

这是我的意图代码:

rvListWa!!.addOnItemTouchListener(RecyclerItemClickListener(this@ShareFileActivity,
            RecyclerItemClickListener.OnItemClickListener { view, position ->

        val url = "https://api.whatsapp.com/send?phone=62"+tempDatas!![position].custHpWa
        val intent = Intent(Intent.ACTION_VIEW)
        intent.data = Uri.parse(url)
        intent.putExtra(Intent.EXTRA_TEXT, "This is an example of the text that will be sended")
        startActivity(intent)

    }))

它已经成功地进入了whatsapp的公开对话中,但没有成功。

这个问题有什么解决办法吗?尽早。

最佳答案

这可以不用Intent.EXTRA_TEXT来完成

试试这个

val msg = "This is going to be the message"
val url = "https://api.whatsapp.com/send?phone=62"+tempDatas!![position].custHpWa + "&text="+msg
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
startActivity(intent)

要么

添加intent.setType("text/plain")

07-24 09:49
查看更多