我的应用程序中有一个部分,我使用按钮发送电子邮件,但由于某种原因,意图不起作用,我不明白为什么。
binding.IvMail.setOnClickListener {
val email = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject))
.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_text))
if (activity?.packageManager?.resolveActivity(email, 0) != null) {
startActivity(email)
}
}
我已经搜索了其他方法来做这件事,但每个人都在使用意图。
3条答案
按热度按时间jei2mxaa1#
xqnpmsa82#
您必须使用
ACTION_SENDTO
而不是ACTION_SEND
。请参阅下面的新代码:
如果尚未解决,请通知我
sc4hvdpw3#
您的代码没有问题。如果它没有运行,则可能是您的if语句未得到满足,正在跳过Intent解析。
您可以执行以下操作来确定问题:
1.通过设置断点并运行如下调试应用程序,在到达代码块时进行调试:
1.通过设置日志并在logcat工具中查找它们,记录是否达到上述代码块,如下所示:
1.您还可以在Logcat中查找运行Intent时发生的错误。