package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class SendMail extends Activity {
/** Called when the activity is first created. */
private EditText mMailTo;
private EditText mMailContent;
private Button mSend;
private String[] strEmailReciver;
private String strEmailBody;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSend = (Button) findViewById(R.id.mSend);
mMailTo = (EditText) findViewById(R.id.mMailTo);
mMailContent = (EditText) findViewById(R.id.mMailContent);
mSend.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("plain/text");
strEmailReciver = new String[] { mMailTo.getText().toString() };
strEmailBody = mMailContent.getText().toString();
intent.putExtra(android.content.Intent.EXTRA_EMAIL,
strEmailReciver);
intent.putExtra(android.content.Intent.EXTRA_TEXT, strEmailBody);
startActivity(Intent.createChooser(intent, getResources()
.getString(R.string.str_message)));
}
});
}
}
main.xml:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="30px" android:text="收件人" />
<EditText android:id="@+id/mMailTo" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="21413244@qq.com" />
<TextView android:layout_width="fill_parent"
android:layout_height="30px" android:text="邮件内容" />
<EditText android:id="@+id/mMailContent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="这里是邮件内容!!" />
<Button android:id="@+id/mSend" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_centerInParent="true"
android:text="发送" />
</LinearLayout>
简单发送邮件例子