public static Intent createEmailAttendeesIntent(Resources resources, String eventTitle,
                                                    String body, List<String> toEmails, List<String> ccEmails, String ownerAccount) {
        List<String> toList = toEmails;
        List<String> ccList = ccEmails;
        if (toEmails.size() <= 0) {
            if (ccEmails.size() <= 0) {
                // TODO: Return a SEND intent if no one to email to, to at least populate
                // a draft email with the subject (and no recipients).
                throw new IllegalArgumentException("Both toEmails and ccEmails are empty.");
            }
            // Email app does not work with no "to" recipient.  Move all 'cc' to 'to'
            // in this case.
            toList = ccEmails;
            ccList = null;
        }
        // Use the event title as the email subject (prepended with 'Re: ').
        String subject = null;
        if (eventTitle != null) {
            subject = resources.getString(R.string.email_subject_prefix) + eventTitle;
        }
        // Use the SENDTO intent with a 'mailto' URI, because using SEND will cause
        // the picker to show apps like text messaging, which does not make sense
        // for email addresses.  We put all data in the URI instead of using the extra
        // Intent fields (ie. EXTRA_CC, etc) because some email apps might not handle
        // those (though gmail does).
        Uri.Builder uriBuilder = new Uri.Builder();
        uriBuilder.scheme("mailto");
        // We will append the first email to the 'mailto' field later (because the
        // current state of the Email app requires it).  Add the remaining 'to' values
        // here.  When the email codebase is updated, we can simplify this.
        if (toList.size() > 1) {
            for (int i = 1; i < toList.size(); i++) {
                // The Email app requires repeated parameter settings instead of
                // a single comma-separated list.
                uriBuilder.appendQueryParameter("to", toList.get(i));
            }
        }
        // Add the subject parameter.
        if (subject != null) {
            uriBuilder.appendQueryParameter("subject", subject);
        }
        // Add the subject parameter.
        if (body != null) {
            uriBuilder.appendQueryParameter("body", body);
        }
        // Add the cc parameters.
        if (ccList != null && ccList.size() > 0) {
            for (String email : ccList) {
                uriBuilder.appendQueryParameter("cc", email);
            }
        }
        // Insert the first email after 'mailto:' in the URI manually since Uri.Builder
        // doesn't seem to have a way to do this.
        String uri = uriBuilder.toString();
        if (uri.startsWith("mailto:")) {
            StringBuilder builder = new StringBuilder(uri);
            builder.insert(7, Uri.encode(toList.get(0)));
            uri = builder.toString();
        }
        // Start the email intent.  Email from the account of the calendar owner in case there
        // are multiple email accounts.
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
        emailIntent.putExtra("fromAccountString", ownerAccount);
        // Workaround a Email bug that overwrites the body with this intent extra.  If not
        // set, it clears the body.
        if (body != null) {
            emailIntent.putExtra(Intent.EXTRA_TEXT, body);
        }
        return Intent.createChooser(emailIntent, resources.getString(R.string.email_picker_label));
    }
public static Intent createEmailAttendeesIntent(Resources resources, String eventTitle,
                                                    String body, List<String> toEmails, List<String> ccEmails, String ownerAccount) {
        List<String> toList = toEmails;
        List<String> ccList = ccEmails;
        if (toEmails.size() <= 0) {
            if (ccEmails.size() <= 0) {
               
               
                throw new IllegalArgumentException("Both toEmails and ccEmails are empty.");
            }
           
           
            toList = ccEmails;
            ccList = null;
        }
       
        String subject = null;
        if (eventTitle != null) {
            subject = resources.getString(R.string.email_subject_prefix) + eventTitle;
        }
       
       
       
       
       
        Uri.Builder uriBuilder = new Uri.Builder();
        uriBuilder.scheme("mailto");
       
       
       
        if (toList.size() > 1) {
            for (int i = 1; i < toList.size(); i++) {
               
               
                uriBuilder.appendQueryParameter("to", toList.get(i));
            }
        }
       
        if (subject != null) {
            uriBuilder.appendQueryParameter("subject", subject);
        }
       
        if (body != null) {
            uriBuilder.appendQueryParameter("body", body);
        }
       
        if (ccList != null && ccList.size() > 0) {
            for (String email : ccList) {
                uriBuilder.appendQueryParameter("cc", email);
            }
        }
       
       
        String uri = uriBuilder.toString();
        if (uri.startsWith("mailto:")) {
            StringBuilder builder = new StringBuilder(uri);
            builder.insert(7, Uri.encode(toList.get(0)));
            uri = builder.toString();
        }
       
       
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
        emailIntent.putExtra("fromAccountString", ownerAccount);
       
       
        if (body != null) {
            emailIntent.putExtra(Intent.EXTRA_TEXT, body);
        }
        return Intent.createChooser(emailIntent, resources.getString(R.string.email_picker_label));
    }
public static intent createemailattendeesintent(resources resources, string eventtitle, string body, list<string> toemails, list<string> ccemails, string owneraccount) { list<string> tolist = toemails; list<string> cclist = ccemails; if (toemails.size() <= 0) { if (ccemails.size() <= 0) { throw new illegalargumentexception("both toemails and ccemails are empty."); } tolist = ccemails; cclist = null; } string subject = null; if (eventtitle != null) { subject = resources.getstring(r.string.email_subject_prefix) + eventtitle; } uri.builder uribuilder = new uri.builder(); uribuilder.scheme("mailto"); if (tolist.size() > 1) { for (int i = 1; i < tolist.size(); i++) { uribuilder.appendqueryparameter("to", tolist.get(i)); } } if (subject != null) { uribuilder.appendqueryparameter("subject", subject); } if (body != null) { uribuilder.appendqueryparameter("body", body); } if (cclist != null && cclist.size() > 0) { for (string email : cclist) { uribuilder.appendqueryparameter("cc", email); } } string uri = uribuilder.tostring(); if (uri.startswith("mailto:")) { stringbuilder builder = new stringbuilder(uri); builder.insert(7, uri.encode(tolist.get(0))); uri = builder.tostring(); } intent emailintent = new intent(intent.action_sendto, uri.parse(uri)); emailintent.putextra("fromaccountstring", owneraccount); if (body != null) { emailintent.putextra(intent.extra_text, body); } return intent.createchooser(emailintent, resources.getstring(r.string.email_picker_label)); }