android 发送e-mail实例

主布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="这是一个发送Email的示例"/>
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="收信人"/>
        <EditText android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ed_receiver"
            android:hint="输入收信人Email"/>
    </LinearLayout>
    
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="主 题"/>
        <EditText android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/ed_emailSubject"
            android:hint="输入信件主题"/>
    </LinearLayout>
    <EditText android:layout_width="fill_parent"
        android:layout_height="250px"
        android:id="@+id/ed_emailBody"
        android:hint="输入新建内容"/>
    <Button android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bt_send"
        android:text="发  送"/>

</LinearLayout>

主活动类EmailActivity.java:

package com.example.ch10;

import com.example.baseexample.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EmailActivity extends Activity {
	private EditText ed_receiver,ed_emailSubject,ed_emailBody;
	private Button bt_send;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch10_email);
		
		ed_receiver = (EditText)findViewById(R.id.ed_receiver);
		ed_emailSubject = (EditText)findViewById(R.id.ed_emailSubject);
		ed_emailBody = (EditText)findViewById(R.id.ed_emailBody);
		bt_send = (Button)findViewById(R.id.bt_send);
		
		bt_send.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View arg0) {
				String[] emailReciver = new String[]{ed_receiver.getText().toString()};
				String emailSubject = ed_emailSubject.getText().toString();
				String emailBody = ed_emailBody.getText().toString();
				
				Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
				emailIntent.setType("plain/text");
				emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailReciver);
				emailIntent.putExtra(android.content.Intent.EXTRA_CC, "test");
				emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, emailSubject);
				emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody);
				startActivity(Intent.createChooser(emailIntent, "mail test"));
			}
			
		});
	}
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值