In Android, Intent is used to call other programs for related processing. Of course, Email is no exception.
In Android, there are three types of Intent for calling Email:
Intent. ACTION_SENDTO send without attachment
Intent. ACTION_SEND send with attachment
Intent. ACTION_SEND_MULTIPLE send with multiple attachments
Of course, the so-called call Email only means that the Email can receive Intent and do these things. Other applications may also implement related functions. Therefore, during execution, the Select box is displayed.
1. Use SENTTO to send
Intent data = new Intent (Intent. ACTION_SENDTO); data. setData (Uri. parse ("mailto: 455245521@qq.com"); data. putExtra (Intent. EXTRA_SUBJECT, "this is the title"); data. putExtra (Intent. EXTRA_TEXT, "this is the content"); startActivity (data );
You can set the mail parameters to putExtra in Intent.
2. SEND with SEND
Intent intent = new Intent(Intent.ACTION_SEND);String[] tos = { "fdafdafa@gmail.com" }; String[] ccs = { "gegeff@gmail.com" }; String[] bccs = {"fdafda@gmail.com"};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:///sdcard/Chrysanthemum.jpg"));intent.setType("image/*");intent.setType("message/rfc882");Intent.createChooser(intent, "Choose Email Client");startActivity(intent);
It is very simple. There are recipients, CC users, and BCC in the mail. That is, pass
Intent. EXTRA_EMAIL,
Intent. EXTRA_CC,
Intent. EXTRA_BCC
To putExtra.
For sending a single attachment, Intent. EXTRA_STREAM is used to set the URL Uri of the attachment.
3. Use SEND_MULTIPLE to send multiple attachments
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);String[] tos = { "wingfourever@gmail.com" }; String[] ccs = { "tongyue@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");ArrayList<Uri> imageUris = new ArrayList<Uri>();imageUris.add(Uri.parse("file:///sdcard/Chrysanthemum.jpg"));imageUris.add(Uri.parse("file:///sdcard/Desert.jpg"));intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);intent.setType("image/*");intent.setType("message/rfc882");Intent.createChooser(intent, "Choose Email Client");startActivity(intent);
When sending multiple attachments, you can use putParcelableArrayListExtra to set the Uri List of multiple attachments. In fact, it is quite simple.
The following figure shows the running effect on Samsung galaxy tab 2 10.1: