传递信息的Action是Intent.ACTION_SEND。
代码如下:
- Intent sendEmailIntent = new Intent(Intent.ACTION_SEND);
- String subject = "subject ";
- String body = "body ";
- String[] extra = new String[] {"111@bbb.com","222@bbb.com","333@bbb.com"};
- sendEmailIntent .putExtra(Intent.EXTRA_EMAIL, extra[0]);
- sendEmailIntent .putExtra(Intent.EXTRA_CC, extra[1]);
- sendEmailIntent .putExtra(Intent.EXTRA_BCC, extra[2]);
- sendEmailIntent .putExtra(Intent.EXTRA_SUBJECT, subject);
- sendEmailIntent .putExtra(Intent.EXTRA_TEXT, body);
- sendEmailIntent .setType("text/plain");
- startActivity(sendEmailIntent);
Intent sendEmailIntent = new Intent(Intent.ACTION_SEND);
String subject = "subject ";
String body = "body ";
String[] extra = new String[] {"111@bbb.com","222@bbb.com","333@bbb.com"};
sendEmailIntent .putExtra(Intent.EXTRA_EMAIL, extra[0]);//发送目标
sendEmailIntent .putExtra(Intent.EXTRA_CC, extra[1]); //抄送
sendEmailIntent .putExtra(Intent.EXTRA_BCC, extra[2]); //暗送
sendEmailIntent .putExtra(Intent.EXTRA_SUBJECT, subject);//标题
sendEmailIntent .putExtra(Intent.EXTRA_TEXT, body);//内容
sendEmailIntent .setType("text/plain");//指定内容是纯文本
//sendEmailIntent .setType("image/png");//指定内容是图片
startActivity(sendEmailIntent);
//也可自定义选择器
//startActivity(Intent.createChooser(sendEmailIntent, "请选择发送软件"));
写成方法:
- private static void sendEmail(Context context, String[] to, String subject,
- String body) {
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- if (to != null) {
- email.putExtra(android.content.Intent.EXTRA_EMAIL, to);
- }
- if (subject != null) {
- email.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
- }
- if (body != null) {
- email.putExtra(android.content.Intent.EXTRA_TEXT, body);
- }
- email.setType("text/plain");
- context.startActivity(Intent.createChooser(emailIntent , "请选择发送软件"));
- }
private static void sendEmail(Context context, String[] to, String subject,
String body) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
if (to != null) {
email.putExtra(android.content.Intent.EXTRA_EMAIL, to);
}
if (subject != null) {
email.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
}
if (body != null) {
email.putExtra(android.content.Intent.EXTRA_TEXT, body);
}
email.setType("text/plain");
context.startActivity(Intent.createChooser(emailIntent , "请选择发送软件"));
}
若用到读写权限:
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">uses-permission>
阅读(594) | 评论(1) | 转发(0) |