通过Intent打开gmail
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("[email protected] /cdn-cgi/l/email-protection"));
intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_CC, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
intent.putExtra(Intent.EXTRA_BCC, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
intent.putExtra(Intent.EXTRA_SUBJECT, "your subject goes here...");
intent.putExtra(Intent.EXTRA_TEXT, "Your message content goes here...");
startActivity(intent);
只是通过EXTRA_CC
& EXTRA_BCC
在意图论证中
Edit
以下答案适用于 Android 11
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");
intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");
startActivity(intent);
Edit 2
val selectorIntent = Intent(Intent.ACTION_SENDTO)
selectorIntent.data = Uri.parse("mailto:")
val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected] /cdn-cgi/l/email-protection"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here...")
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email Body...")
emailIntent.selector = selectorIntent
activity!!.startActivity(Intent.createChooser(emailIntent, "Send email..."))