Android call system Email-multiple attachments

Source: Internet
Author: User

As we all know, the Intent is used to call other programs in Android 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
 
[Java]
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 content ");
StartActivity (data );
You can set the mail parameters to putExtra in Intent.
 
2. SEND with SEND
 
[Java]
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
[Java]
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:
 
 
Email sending is used in many Android applications, which are as common as Weibo sharing. You only need to know a little about it. After all, it is easy.
 
Reprinted please indicate the source: http://blog.csdn.net/ml3947/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.