We all know that calling other programs in Android for relevant processing is almost all using Intent, so 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
[Java]Copy codeThe Code is as follows: Intent data = new Intent (Intent. ACTION_SENDTO );
Data. setData (Uri. parse ("mailto: way.ping.li@gmail.com "));
Data. putExtra (Intent. EXTRA_SUBJECT, "this is the title ");
Data. putExtra (Intent. EXTRA_TEXT, "this is content ");
StartActivity (data );
Intent data = new Intent (Intent. ACTION_SENDTO );
Data. setData (Uri. parse ("mailto: way.ping.li@gmail.com "));
Data. putExtra (Intent. EXTRA_SUBJECT, "this is the title ");
Data. putExtra (Intent. EXTRA_TEXT, "this is content ");
StartActivity (data );
You can set the mail parameters to putExtra in Intent.
2. SEND with SEND
[Java]Copy codeThe Code is as follows: Intent intent = new Intent (Intent. ACTION_SEND );
String [] tos = {"way.ping.li@gmail.com "};
String [] ccs = {"way.ping.li@gmail.com "};
String [] bccs = {"way.ping.li@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: // 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 = {"way.ping.li@gmail.com "};
String [] ccs = {"way.ping.li@gmail.com "};
String [] bccs = {"way.ping.li@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: // mnt/sdcard/a.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 set putExtra, and send a single attachment, use Intent. EXTRA_STREAM to set the URL Uri of the attachment.
3. Use SEND_MULTIPLE to send multiple attachments
[Java]Copy codeThe Code is as follows: 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 ");
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 = {"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 ");
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 );
When sending multiple attachments, you can use putParcelableArrayListExtra to set the Uri List of multiple attachments. In fact, it is quite simple.