Android调用系统的发邮件功能的小例子
package com.example.myapi.email;
import java.util.arraylist;
import java.util.list;
import android.content.context;
import android.content.intent;
import android.net.uri;
public class sendemailutils {
private sendemailutils(){}
private static sendemailutils instance;
public static sendemailutils getinstance(){
synchronized (sendemailutils.class) {
if(instance == null){
instance = new sendemailutils();
}
}
return instance;
}
/**
* 这是一个简单的测试,不支持带附件,多人,抄送发送等。
* @param context
*/
public void sendemail(context context){
intent intent = new intent();
intent.setdata(uri.parse("mailto:"));
/*设置邮件的标题*/
intent.putextra(intent.extra_subject, "别紧张,这仅仅是一个测试!");
/*设置邮件的内容*/
intent.putextra(intent.extra_text, "测试打开系统邮箱并将发送的标题和内容自动填充到邮箱,并发送邮件,");
//开始调用
context.startactivity(intent);
}
/**
* 发邮件,带抄送,和密送,并带上个附件
* @param context
*/
public void sendemailduo(context context){
intent intent = new intent(intent.action_send);
// intent.setdata(uri.parse("mailto:"));
string[] tos = { "yw.1@163.com" };
string[] ccs = { "yw.2@163.com" };
string[] bccs = {"yw.3@163.com"};
intent.putextra(intent.extra_email, tos); //收件者
intent.putextra(intent.extra_cc, ccs); //抄送这
intent.putextra(intent.extra_bcc, bccs); //密送这
intent.putextra(intent.extra_text, "邮件内容");
intent.putextra(intent.extra_subject, "邮件标题");
intent.putextra(intent.extra_stream, uri.parse("file:///mnt/sdcard/a.jpg"));
intent.settype("image/*");
intent.settype("message/rfc882");
intent.createchooser(intent, "choose email client");
context.startactivity(intent);
}
/**
* 多附件发送
* @param conext
*/
public void sendfujian(context conext){
intent intent = new intent(intent.action_send_multiple);
string[] tos = { "way.ping.li@gmail.com" };
string[] ccs = { "way.ping.li@gmail.com" };
intent.putextra(intent.extra_email, tos);
intent.putextra(intent.extra_cc, ccs);
intent.putextra(intent.extra_text, "body");
intent.putextra(intent.extra_subject, "subject");
list<uri> imageuris = new arraylist<uri>();
imageuris.add(uri.parse("file:///mnt/sdcard/a.jpg"));
imageuris.add(uri.parse("file:///mnt/sdcard/b.jpg"));
intent.putextra(intent.extra_stream, imageuris);
intent.settype("image/*");
intent.settype("message/rfc882");
intent.createchooser(intent, "choose email client");
conext.startactivity(intent);
}
}