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

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:

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/


---------------------------------

Recently, a project on the company's tablet needs to use email to send multi-page images exported from logs, and other functions such as Weibo sharing. So I read a little bit about sending multiple attachments by calling email, and wrote this blog.


I was going to play with my colleagues this weekend, but it seems that it would take two days. If so, I will continue to write the related blog of javafx.



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.