手机交互应用服务(邮件)

1.纯文本发送:

  使用这种方式会调用其他的邮件发送程序,相当于点击了系统的邮件App或其他的邮件客户端(qq、Gmail、网易等)

public void sendEmail(String title, String content) {
    Intent email = new Intent(Intent.ACTION_SENDTO);
    email.setData(Uri.parse("mailto:happyhaoye@gmail.com"));
    email.putExtra(Intent.EXTRA_SUBJECT, title);
    email.putExtra(Intent.EXTRA_TEXT, content);
    startActivity(Intent.createChooser(email, "请选择邮件发送程序!"));
}

2.带附件的发送:

  public void sendEmailWithAttachment(String title, String content, File attachment) {
        Intent   email      = new Intent(Intent.ACTION_SEND);
        String[] emailAddrs = new String[]{"happyhaoye@gmail.com","hehehehe@163.com"};
        
        email.setType("application/octet-stream");//---设置邮件类型:带附件
                
        email.putExtra(Intent.EXTRA_EMAIL, emailAddrs);
        email.putExtra(Intent.EXTRA_SUBJECT, title);
        email.putExtra(Intent.EXTRA_TEXT, content);
        email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
        
        startActivity(Intent.createChooser(email, "请选择邮件发送程序!"));
    }
原文地址:https://www.cnblogs.com/laishenghao/p/5243254.html