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

前端 未结 5 1740
無奈伤痛
無奈伤痛 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:10

    try out this code, it worked for me.

    Intent intent = new Intent(Intent.ACTION_SENDTO);
                intent.setData(Uri.parse("mailto:")); // only email apps should handle this
                intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
                intent.putExtra(Intent.EXTRA_SUBJECT, "Subject here");
                intent.putExtra(Intent.EXTRA_TEXT,"Body Here");
                if (intent.resolveActivity(getPackageManager()) != null) {
                    startActivity(intent);
                }
    

    also add intent filter in android manifest.

    
    
        
        
        
    
    

提交回复
热议问题