安卓跳转邮件页面

在Android中,调用Email有三种类型的Intent: Intent.ACTION_SENDTO 无附件的发送 Intent.ACTION_SEND 带附件的发送 Intent.ACTION_SEND_MULTIPLE 带有多附件的发送 

【方法1】使用SENTTO发送 

1
2
3
4
5
6
7
8
9
10
Intent data= new  Intent(Intent.ACTION_SENDTO); 
data.setData(Uri.parse( "mailto:[email protected]" )); 
data.putExtra(Intent.EXTRA_SUBJECT,  "这是标题" ); 
data.putExtra(Intent.EXTRA_TEXT,  "这是内容" ); 
startActivity(data); 
Intent data= new  Intent(Intent.ACTION_SENDTO); 
data.setData(Uri.parse( "mailto:[email protected]" )); 
data.putExtra(Intent.EXTRA_SUBJECT,  "这是标题" ); 
data.putExtra(Intent.EXTRA_TEXT,  "这是内容" ); 
startActivity(data);

【方法2】使用SEND发送 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Intent intent =  new  Intent(Intent.ACTION_SEND); 
String[] tos = {  "[email protected]"  }; 
String[] ccs = {  "[email protected]"  }; 
String[] bccs = { "[email protected]" }; 
intent.putExtra(Intent.EXTRA_EMAIL, tos); 
intent.putExtra(Intent.EXTRA_CC, ccs); 
intent.putExtra(Intent.EXTRA_BCC, bccs); 
intent.putExtra(Intent.EXTRA_TEXT,  "body" ); 
intent.putExtra(Intent.EXTRA_SUBJECT,  "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" ); 
startActivity(intent); 
Intent intent =  new  Intent(Intent.ACTION_SEND); 
String[] tos = {  "[email protected]"  }; 
String[] ccs = {  "[email protected]"  }; 
String[] bccs = { "[email protected]" }; 
intent.putExtra(Intent.EXTRA_EMAIL, tos); 
intent.putExtra(Intent.EXTRA_CC, ccs); 
intent.putExtra(Intent.EXTRA_BCC, bccs); 
intent.putExtra(Intent.EXTRA_TEXT,  "body" ); 
intent.putExtra(Intent.EXTRA_SUBJECT,  "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" ); 
startActivity(intent);

很简单,发送邮件中,有收件者,抄送者,密送者。 也就是分别通过 Intent.EXTRA_EMAIL, Intent.EXTRA_CC, Intent.EXTRA_BCC 来进行putExtra来设定的,而单个附件的发送,则使用Intent.EXTRA_STREAM来设置附件的地址Uri。 【方法3】使用SEND_MULTIPLE来进行多附件的发送 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Intent intent =  new  Intent(Intent.ACTION_SEND_MULTIPLE); 
String[] tos = {  "[email protected]"  }; 
String[] ccs = {  "[email protected]"  }; 
intent.putExtra(Intent.EXTRA_EMAIL, tos); 
intent.putExtra(Intent.EXTRA_CC, ccs); 
intent.putExtra(Intent.EXTRA_TEXT,  "body" ); 
intent.putExtra(Intent.EXTRA_SUBJECT,  "subject" ); 
ArrayList<uri> imageUris =  new  ArrayList<uri>(); 
imageUris.add(Uri.parse( "file:///mnt/sdcard/a.jpg" )); 
imageUris.add(Uri.parse( "file:///mnt/sdcard/b.jpg" )); 
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); 
intent.setType( "image/*" ); 
intent.setType( "message/rfc882" ); 
Intent.createChooser(intent,  "Choose Email Client" ); 
startActivity(intent); 
Intent intent =  new  Intent(Intent.ACTION_SEND_MULTIPLE); 
String[] tos = {  "[email protected]"  }; 
String[] ccs = {  "[email protected]"  }; 
intent.putExtra(Intent.EXTRA_EMAIL, tos); 
intent.putExtra(Intent.EXTRA_CC, ccs); 
intent.putExtra(Intent.EXTRA_TEXT,  "body" ); 
intent.putExtra(Intent.EXTRA_SUBJECT,  "subject" ); 
ArrayList<uri> imageUris =  new  ArrayList<uri>(); 
imageUris.add(Uri.parse( "file:///mnt/sdcard/a.jpg" )); 
imageUris.add(Uri.parse( "file:///mnt/sdcard/b.jpg" )); 
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris); 
intent.setType( "image/*" ); 
intent.setType( "message/rfc882" ); 
Intent.createChooser(intent,  "Choose Email Client" ); 
startActivity(intent);

猜你喜欢

转载自blog.csdn.net/u012588160/article/details/80632217