假设我在布局中有一个按钮和一个编辑文本。如何发送一封电子邮件,说明某些消息到该地址,这是android studio中的编辑文本?
答案 0 :(得分:2)
String email = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_SENDTO,
Uri.parse("mailto:" + email));
intent.putExtra(Intent.EXTRA_SUBJECT, "Enter subject here");
intent.putExtra(Intent.EXTRA_TEXT, "Enter email body here");
startActivity(Intent.createChooser(intent,
"Choose email client")));
答案 1 :(得分:0)
首先从您的电子邮件edittext获取文字。然后使用此电子邮件向您发送电子邮件。
String email = emailfield.getText().toString()
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , email);
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "No email clients installed.", Toast.LENGTH_SHORT).show();
}