Android发邮件
来源:互联网 发布:mac中英文切换 编辑:程序博客网 时间:2024/05/21 09:59
Android系统内置了Gmail引擎来发送邮件,也可以使用SMTP来发送E-mail,下面演示的是使用Gmail客户端来发送E-mail。
1、新建一个xml文件main.xml的 布局文件
wrap-content是跟随内容变化。
fill_parent是跟随父控件变化,其父控件是嵌套该控件的控件
<?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="wrap_content" android:layout_height="wrap_content" android:text="收件人:" android:id="@+id/TextView01"></TextView><EditTextandroid:id="@+id/et_to"android:layout_width="fill_parent"android:layout_height="wrap_content"></EditText><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="主题:" android:id="@+id/TextView02" ></TextView><EditTextandroid:id="@+id/et_subject"android:layout_width="fill_parent"android:layout_height="wrap_content"></EditText><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="内容" android:id="@+id/TextView03"></TextView><EditTextandroid:id="@+id/et_content"android:layout_width="fill_parent"android:layout_height="wrap_content"></EditText><Button android:id="@+id/btn_send"android:text="发送"android:layout_width="wrap_content"android:layout_height="wrap_content"></Button></LinearLayout>
2、MainActivity.java
package com.ex;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.widget.Button;import android.widget.EditText;import android.view.*;import android.view.View.OnClickListener;public class MainActivity extends Activity {private EditText et_to, et_subject, et_content;private Button btn_send;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);et_to = (EditText) findViewById(R.id.et_to);et_subject = (EditText) findViewById(R.id.et_subject);et_content = (EditText) findViewById(R.id.et_content);btn_send = (Button) findViewById(R.id.btn_send);//button的监听器btn_send.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {String to = et_to.getText().toString();String subject = et_subject.getText().toString();String content = et_content.getText().toString();// 创建IntentIntent emailIntent = new Intent(android.content.Intent.ACTION_SEND);//设置内容类型emailIntent.setType("plain/text");//设置额外信息emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { to });emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);//启动ActivitystartActivity(Intent.createChooser(emailIntent, "发送邮件..."));}});}}
说明:这里是使用Intent当作信使,而Intent是调用了内置的ACTION_SEND.此外
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { to });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);
三个额外信息,在Android里有EXTRA_EMAIL的内置信息,直接使用即可
3、效果
- Android 发邮件
- Android 发邮件
- Android 发邮件
- Android发邮件
- Android 发邮件
- Android 发邮件
- Android发邮件
- Android如何发邮件?
- android应用发邮件
- Android 后台发邮件
- Android发邮件代码实例
- Android 发邮件ZZ
- 实现Android后台发邮件
- Android进阶(十)Android 发邮件
- Android调用系统的发邮件方法
- Android 调用系统email程序发邮件
- Android调用系统的发邮件方法
- android实现后台自动发邮件功能
- 我的2011——我的第一个年终总结
- 要毕业了
- 被Microsoft® .NET: Architecting Applications for the Enterprise提及的
- ubuntu/centos环境下玩android系统(四): Android模拟器中运行hello world和贪吃蛇snake!
- 简单基于HttpListener的Web服务器实例
- Android发邮件
- Hibernate面试题 --- Hibernate中复合主键的配置
- vs 2005 2008 工程中打不开qrc文件的解决办法.
- Jdk1.6和tomcat 6的安装
- XML 中CDATA段 #PCDATA CDATA类型
- JavaWeb读取context param
- 总结下linux中一些入门级shell编程实例
- Null
- 关于try、catch、finally语句块中含有return语句的几点说明