Android Studio mailto Intent doesn't show subject and mail body

前端 未结 5 1742
無奈伤痛
無奈伤痛 2020-12-11 02:45

I\'m trying to send an e-mail from my Android App. With the click on a button, gmail should open and show a new email with my previously defined recipient, subject and email

5条回答
  •  爱一瞬间的悲伤
    2020-12-11 03:33

    try this code

        val emailIntent = Intent(Intent.ACTION_SEND)
        emailIntent.setType("text/plain")
        emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("jon@example.com")) 
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email subject")
        emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message text")
        val packageManager = packageManager
        val activities = packageManager.queryIntentActivities(emailIntent, 0)
        val isIntentSafe = activities.size > 0
        if (isIntentSafe) {
            startActivity(emailIntent);
        }else{
            Log.d("MainActivty","Email App not installed");
        }
    

提交回复
热议问题