I'm trying to send a message to Whatsapp from another app, that I achieved with the following code, and it's working fine:
To send simple messages refer: Send text to specific contact programmatically (whatsapp)
fun sendWhatsappMessage(phone: String, message: String) {
val packageManager = packageManager
val i = Intent(Intent.ACTION_VIEW)
try {
val url = "https://api.whatsapp.com/send?phone=$phone&text=" + URLEncoder.encode(
message,
"UTF-8"
)
i.setPackage("com.whatsapp")
i.data = Uri.parse(url)
if (i.resolveActivity(packageManager) != null) {
sendBroadcast(i)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
My question is, is there a way to send a complex message, such as contact info through the message?