Example usage for android.content Intent EXTRA_EMAIL

List of usage examples for android.content Intent EXTRA_EMAIL

Introduction

In this page you can find the example usage for android.content Intent EXTRA_EMAIL.

Prototype

String EXTRA_EMAIL

To view the source code for android.content Intent EXTRA_EMAIL.

Click Source Link

Document

A String[] holding e-mail addresses that should be delivered to.

Usage

From source file:Main.java

public static void sendEmail(Context context, String receiver, String subject, String body) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { receiver });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    try {/*from  ww  w. ja  v a  2 s .  co  m*/
        context.startActivity(Intent.createChooser(intent, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
    }
}

From source file:Main.java

@NonNull
public static Intent sendEmail(@NonNull String[] to, @NonNull String subject, @NonNull String body,
        @Nullable List<Uri> attachments) {
    final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, to);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, body);
    if (attachments != null && !attachments.isEmpty()) {
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<Parcelable>(attachments));
    }//  w  w w  .  j  a  v  a  2s.com
    return intent;
}

From source file:Main.java

@NonNull
public static Intent sendEmail(@NonNull String[] to, @NonNull String subject, @NonNull String body,
        @Nullable List<Uri> attachments) {
    final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, to);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    final ArrayList<CharSequence> extraText = new ArrayList<>(1);
    extraText.add(body);//from w w  w .  j a  v a  2s  .c  o m
    intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, extraText);
    if (attachments != null && !attachments.isEmpty()) {
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<Parcelable>(attachments));
    }
    return intent;
}

From source file:Main.java

public static void sendMail(Context context, String[] mail, String subject, String body) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    //        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
    //        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    //        i.putExtra(Intent.EXTRA_TEXT   , "body of email");
    i.putExtra(Intent.EXTRA_EMAIL, mail);
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, body);
    try {/*  w w  w. jav a2s  .  c om*/
        context.startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

/**
 * Easily create email intent//from  w  ww .j av  a2  s . co m
 * 
 * @param recipientsList
 * @param ccList
 * @param subject
 * @param htmlBody
 * @return email intent chooser
 */
public static Intent createEmailIntent(List<String> recipientsList, List<String> ccList, String subject,
        CharSequence htmlBody) {
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    // emailIntent.setData(Uri.parse("mailto:"));

    if (recipientsList != null) {
        for (String email : recipientsList) {
            emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
        }
    }
    if (ccList != null) {
        for (String email : ccList) {
            emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
        }
    }
    if (subject != null)
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (htmlBody != null)
        emailIntent.putExtra(Intent.EXTRA_TEXT, htmlBody);

    return emailIntent;
}

From source file:Main.java

public static Intent sendEmail(String[] to, String subject, String body) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, to);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, body);
    return intent;
}

From source file:Main.java

public static Intent sendEmail(String[] to, String subject, String body) {
    final Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
    intent.putExtra(Intent.EXTRA_EMAIL, to);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, body);
    return intent;
}

From source file:Main.java

public static void openMailChooser(Context context, String text, String[] mails, String subject) {
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.putExtra(Intent.EXTRA_TEXT, text);
    mailIntent.putExtra(Intent.EXTRA_EMAIL, mails);
    mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    mailIntent.setType(INTENT_TYPE_MSG);

    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(INTENT_TYPE_TEXT);

    Intent openInChooser = Intent.createChooser(mailIntent, "");

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains(PACKAGE_EMAIL)) {
            mailIntent.setPackage(packageName);
        } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(INTENT_TYPE_TEXT);
            if (packageName.contains(PACKAGE_MMS)) {
                intent.putExtra("subject", subject);
                intent.putExtra("sms_body", text);
                intent.putExtra("address", mails[0]);
                intent.setType(INTENT_TYPE_MSG);
            } else if (packageName.contains(PACKAGE_GMAIL)) {
                intent.putExtra(Intent.EXTRA_TEXT, text);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                intent.putExtra(Intent.EXTRA_EMAIL, mails);
                intent.setType(INTENT_TYPE_MSG);
            }/* w  w  w .j  av a  2  s . c  om*/

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    context.startActivity(openInChooser);
}

From source file:Main.java

public static boolean sendMail(Context context, String destination, String subject, String body) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { destination };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    if (subject != null) {
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    }//  w w  w.j a  v  a  2 s  .  co  m
    if (body != null) {
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    }
    emailIntent.setType("plain/text");

    boolean ret = true;
    try {
        context.startActivity(emailIntent);
    } catch (Exception e) {
        ret = false;
    }
    return ret;
}

From source file:Main.java

/**
 * Drafts an email to the given email address, with the given subject line and message
 * @param context/*www.ja va  2  s  . co m*/
 * @param emailAddress
 * @param subject
 * @param message
 */
public static void emailDeveloper(Context context, String emailAddress, String subject, String message) {

    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddress });
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, message);

    context.startActivity(i);
}