尝试使用意图发送电子邮件时发生崩溃(Kotlin)

当我尝试使用kotlin意图发送电子邮件时,我遇到了崩溃

这是我的功能

/** * intentEmail is called when we need to send email * * @param price int */ fun intentEmail(price: Int) { var intent = Intent(Intent.ACTION_SEND) //intent.putExtra(Intent.EXTRA_EMAIL, addressees) intent.data= Uri.parse("mailto:") intent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for $name") intent.putExtra(Intent.EXTRA_TEXT, createOrderSummary(price)) if(intent.resolveActivity(packageManager) != null){ startActivity(intent) } } 

并在调用startActivity(intent)时发生崩溃

这里是我的LogCat 在这里输入图像描述

也许你的手机不接受这个意图行动。 你应该使用try catch来避免这个崩溃。 您也可以使用手机的其他“发送邮件”应用程序,以便您可以找出正确的意图。

问题在于

var intent =意图(Intent.ACTION_SEND)

当我改变它

var intent = Intent(Intent.ACTION_SENDTO)

它工作得很好,感谢@lampenlampen