Android calls system email to send messages with multiple attachments

Source: Internet
Author: User

Transferred from: http://www.open-open.com/lib/view/open1347005126912.html

As we all know, calling other programs in Android for related processing is the intent used. Of course, email is no exception.

In Android, there are three types of intent called email:

Intent.action_sendto Send without attachments

Intent.action_send Send with Attachment

Intent.action_send_multiple Send with multiple attachments

Of course, the so-called call email, just say that email can receive intent and do these things, there may be other applications to implement the relevant functions, so in the execution of the time, the selection box will appear to choose.

1. Send Using Sentto

?
12345 Intent data=newIntent(Intent.ACTION_SENDTO); data.setData(Uri.parse("mailto:[email protected]")); data.putExtra(Intent.EXTRA_SUBJECT, "这是标题"); data.putExtra(Intent.EXTRA_TEXT, "这是内容"); startActivity(data);

Set the relevant parameters for the message by Putextra to intent.

2. Sending using Send

?
123456789101112131415 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:///sdcard/Chrysanthemum.jpg"));intent.setType("image/*");intent.setType("message/rfc882");Intent.createChooser(intent, "Choose Email Client");startActivity(intent);

Very simple, sent in the mail, there are recipients, CC, the secret sender. That is, separate through

Intent.extra_email,

INTENT.EXTRA_CC,

Intent.extra_bcc

To be set by Putextra.

When sending a single attachment, use Intent.extra_stream to set the address URI of the attachment.

3. Use Send_multiple to send multiple attachments

?
12345678910111213141516 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:///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);</uri></uri>


Send multiple attachments, most of the time, by Putparcelablearraylistextra the URI address list of multiple attachments in the OK. In fact, it is very simple.

Here's how it works on the Samsung Galaxy Tab 2 10.1:

For email use, it's common in many Android apps, as is sharing with Weibo. You just need to know a little bit about it, after all, it's easy.

Android calls system email to send messages with multiple attachments

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.