[Solved] Whatsapp not found with Intent.ACTION_SEND

AlexPes Asks: Whatsapp not found with Intent.ACTION_SEND
Can you please help me to understand why com.whatsapp package is not searchable when using Intent.ACTION_SEND, although it is searchable when usingIntent.ACTION_VIEW


UPDATED. Whatsapp is open and text put into message box for contact specified by phone number but is not sent

Code:
private val PUSH_BUTTON = "You send request for password, please wait"
private var url = "https://api.whatsapp.com/send?phone=$+10987654321&text=${
    URLEncoder.encode("HERE WILL BE A CODE IN THE NEAR FUTURE", "UTF-8")}"

class MainActivity : AppCompatActivity() {

init {
    instance = this
}

companion object {
    private var instance: MainActivity? = null

    fun applicationContext() : Context {
        return instance!!.applicationContext
    }
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val button:Button = findViewById(R.id.button)
    button.setOnClickListener {
        Toast.makeText(applicationContext, PUSH_BUTTON, Toast.LENGTH_LONG).show()
        val packageManager = applicationContext().packageManager
        //intent
        val intent = Intent(Intent.ACTION_VIEW)
        intent.setData(Uri.parse(url))
        intent.setPackage("com.whatsapp")
        if (intent.resolveActivity(packageManager) != null) {
            startActivity(intent)
        } else {
            Toast.makeText(applicationContext, "WhatsApp is not installed", Toast.LENGTH_LONG).show()
        }
    }
}

}


enter image description here

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.