在下面的main.xml中我有一个edittext,我的问题是如何点击发送邮件按钮如何发送邮件,其中To地址是硬编码的。
mail.setOnClickListener(
@Override
public void onClick(View v) {
//How to sendmail to adress someadress@xx.com oblibk of send mail button
});
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="fill_parent">
<EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
<Button android:text="Send Mail" android:id="@+id/mail" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Back" android:id="@+id/back2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
答案 0 :(得分:5)
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"youraddress@aaaaa.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, yourSubject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, yourBodyText);
context.startActivity(Intent.createChooser(intent, "Send mail..."));