【问题标题】:got crash when try to use intent to send email (Kotlin)尝试使用意图发送电子邮件时崩溃(Kotlin)
【发布时间】:2018-01-25 05:59:09
【问题描述】:

当我尝试通过 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

【问题讨论】:

  • 使用 LogCat 检查与您的崩溃相关的 Java 堆栈跟踪:stackoverflow.com/questions/23353173/… 另外,请注意ACTION_SEND 不使用Uri,因此您应该删除intent.data= Uri.parse("mailto:") 行。
  • 您是否在清单文件中添加了权限?
  • @CommonsWare 我附上了 LogCat 也评论了 intent.data 行,但没有崩溃,但应用程序没有做任何事情
  • @SígvardrÓlavrsson 你是指哪些权限?
  • 1.我建议您阅读 android 文档 (developer.android.com/guide/components/…)。它指出,对于没有附件,您应该使用“ACTION_SENDTO”作为操作。

标签: android android-intent kotlin


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    问题出在

    var intent = Intent(Intent.ACTION_SEND)

    当我把它改成

    var intent = Intent(Intent.ACTION_SENDTO)

    感谢@lampenlampen,它运行良好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2017-10-30
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多