Android调用邮件客户端

来源:互联网 发布:db2数据库启停 编辑:程序博客网 时间:2024/06/04 18:31

main.xml如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity" >    <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_centerVertical="true"        android:text="发送邮件" /></RelativeLayout>


mainActivity如下:

package c.c;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;/** * Demo描述: * 调用设备上的邮件客户端发送邮件 * 在此会列出该设备上的所有邮件客户端,供用户选择 */public class MainActivity extends Activity {    private Button mButton;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);init();}    private void init(){    mButton=(Button) findViewById(R.id.button);    mButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {startSendEmail();}});    }    private void startSendEmail() {String address="test@sina.com";String subject="邮件的标题";String body="邮件的内容";String content = "mailto:"+address+"?subject="+subject+"&body="+body;Intent returnIt = new Intent(Intent.ACTION_SENDTO);returnIt.setData(Uri.parse(content));startActivity(Intent.createChooser(returnIt, "Send email tips"));}}


 

原创粉丝点击