gpt4 book ai didi

java - 在android studio中发送邮件

转载 作者:太空宇宙 更新时间:2023-11-04 12:20:10 25 4
gpt4 key购买 nike

我的代码运行完全没有错误,但不符合预期的输出。当它运行时,它应该提供如何发送邮件的选择,但它只为我提供蓝牙和信使,而不是电子邮件。

  protected void sendEmail() {
Toast.makeText(MainActivity.this,"Sending mail", Toast.LENGTH_SHORT).show();
String[] TO = {"xyz@gmail.com"};
String[] CC = {"abc@gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");


emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message :");

try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}

}

最佳答案

使用这个

<小时/>
protected void sendEmail() {

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:aaaaaa@gmail.com"));
emailIntent.putExtra("subject", "Feedback");
emailIntent.putExtra("body", "");
startActivity(emailIntent);


}

关于java - 在android studio中发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38933033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com