可以通过WhatsApp发送超链接吗?

问题描述 投票:0回答:1

我正在开发一个通过 WhatsApp 发送消息和链接的应用程序。为了使外观更加美观,应用程序背后的人员希望以超链接的形式发送文本内的链接。 这可能吗?

目前,我正在向客户发送加入WhatsApp群组的邀请:

private fun shareWhatsAppGroup(mobileNumber: String) {
        val intent = Intent(Intent.ACTION_VIEW)

        val groupUri = sharedPreferences.getString(
            "my_string",
            "https://chat.whatsapp.com/group_link"
        )
        var messageOne = "Rooster Gallery welcomes you 🤍"
        var messageTwo = "Please join our WhatsApp group"
        var messageThree = "By clicking on the following link:"
        var message = messageOne + "\n" + messageTwo + "\n" + messageThree + "\n" + "$groupUri"
        intent.data =
            Uri.parse("https://api.whatsapp.com/send?phone=+962$mobileNumber&text=$message ")
        //intent.setPackage("com.whatsapp")
        startActivity(intent)
        if (!isAccessibilityOn(this, WhatsappAccessibilityService::class.java)) {
            Toast.makeText(this, "Contact don't have whatsapp", Toast.LENGTH_SHORT).show()

            val intent = Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS)
            this.startActivity(intent)
        }
    }
android kotlin text hyperlink whatsapp
1个回答
0
投票

只需对消息进行编码以实现正确的 URL 格式。然后whatsapp会检测到这是一个链接。

var message = "$messageOne\n$messageTwo\n$messageThree\n$groupUri"
val encodedMessage = URLEncoder.encode(message, "UTF-8")
intent.data = Uri.parse("https://api.whatsapp.com/send?phone=+962$mobileNumber&text=$encodedMessage")
© www.soinside.com 2019 - 2024. All rights reserved.