Android calling system Email multi-Attachment

Source: Internet
Author: User

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:

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.