// 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.
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));
    }
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++) {
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);
// 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);
}