4 回答

TA貢獻1744條經驗 獲得超4個贊
// 對于任何應用程序的電子郵件
Intent email= new Intent(Intent.ACTION_SENDTO); email.setData(Uri.parse("mailto:[email protected]")); email.putExtra(Intent.EXTRA_SUBJECT, "Subject"); email.putExtra(Intent.EXTRA_TEXT, "My Email message"); startActivity(email);

TA貢獻1821條經驗 獲得超6個贊
通過 Intent 打開 gmail
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("[email protected]"));
intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_CC, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_BCC, new String[]{"[email protected]"});
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
編輯
以下答案適用于android 11
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");
intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");
startActivity(intent);
編輯 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]"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here...")
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email Body...")
emailIntent.selector = selectorIntent
activity!!.startActivity(Intent.createChooser(emailIntent, "Send email..."))

TA貢獻1831條經驗 獲得超10個贊
// 這是用于 Gmail 應用程序的
Intent email= new Intent(Intent.ACTION_VIEW); email.setType("message/rfc822") .setData(Uri.parse("mailto:[email protected]")) .putExtra(Intent.EXTRA_EMAIL, "[email protected]") .putExtra(Intent.EXTRA_SUBJECT, "Subject") .putExtra(Intent.EXTRA_TEXT, "My Email message") .setPackage("com.google.android.gm"); startActivity(email);

TA貢獻1799條經驗 獲得超6個贊
//這是用gmail打開的
Intent i = new Intent(Intent.ACTION_SENDTO); i.setType("text/plain"); i.setData(Uri.parse("mailto:")); i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); i.putExtra(Intent.EXTRA_SUBJECT, "Mail Subject"); i.putExtra(Intent.EXTRA_TEXT , "massage"); i.setPackage("com.google.android.gm"); try { startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(AnotherActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); }
添加回答
舉報