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 sendMail(Context context, String email) {
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    sendIntent.putExtra(Intent.EXTRA_TEXT, "");
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);//from www.ja  va 2 s. co m
}

From source file:Main.java

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

From source file:Main.java

public static Intent newEmailIntent(Context context, String address, String subject, String body, String cc) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
    intent.putExtra(Intent.EXTRA_TEXT, body);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_CC, cc);
    intent.setType("message/rfc822");
    return intent;
}

From source file:Main.java

public static void sendMail(Context context, String dstAddr, String subject, String text) {
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

    String[] address = { dstAddr };
    emailIntent.putExtra(Intent.EXTRA_EMAIL, address);
    emailIntent.setType("message/rfc822");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:Main.java

public static void sendEmail(String email, Context context) {
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { email };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.setType(PLAIN_TEXT);/*from   w  w w.j  av a 2  s  .c o  m*/
    context.startActivity(emailIntent);
}

From source file:Main.java

public static Intent newSendMultipleAttachmentsIntent(String emailAddress, String subject, String contentBody,
        ArrayList<Uri> uris) {

    final Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
    ei.setType("plain/text");
    ei.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddress });
    ei.putExtra(Intent.EXTRA_SUBJECT, subject);

    //ei.putExtra(Intent.EXTRA_TEXT, contentBody);
    //fix for ClassCastException with Intent.EXTRA_TEXT : https://code.google.com/p/android/issues/detail?id=38303
    //: use list of string not a string
    ArrayList<String> extra_text = new ArrayList<String>();
    extra_text.add(contentBody);//  w  w w.  ja  v a 2 s  .c om
    ei.putExtra(Intent.EXTRA_TEXT, extra_text);

    ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

    return ei;
}

From source file:Main.java

public static void mail(Activity activity, String email, String subject, String content) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);

    if (content != null) {
        intent.putExtra(Intent.EXTRA_TEXT, content);
    }/* ww w  . j  a v  a 2s. c  o  m*/

    final PackageManager manager = activity.getPackageManager();
    final List<ResolveInfo> matches = manager.queryIntentActivities(intent, 0);

    for (ResolveInfo info : matches) {
        if (info.activityInfo.packageName.endsWith(".gm")
                || info.activityInfo.name.toLowerCase().contains("gmail")) {
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        } else if (info.activityInfo.packageName.endsWith(".email")
                || info.activityInfo.name.toLowerCase().contains("email")) {
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        }
    }

    activity.startActivity(intent);
}

From source file:Main.java

public static void feedback(Context context, String feedBackEmailId, String emailSubject, String msg) {

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { feedBackEmailId });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, msg);
    emailIntent.setType("message/rfc822");
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (isIntentAvailable(context, emailIntent)) {
        context.startActivity(emailIntent);
    } else {/*from  www.  j a v  a 2s .  c  om*/
        Toast.makeText(context, "No Email Application Found", Toast.LENGTH_LONG).show();
    }
}

From source file:Main.java

public static void shareToGMail(Context context, String[] email, String subject, String content) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
    ResolveInfo best = null;//  www  .j a  va2 s .c o  m
    for (final ResolveInfo info : matches)
        if (info.activityInfo.packageName.endsWith(".gm")
                || info.activityInfo.name.toLowerCase().contains("gmail"))
            best = info;
    if (best != null)
        emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
    context.startActivity(emailIntent);
}

From source file:Main.java

public static void startEmailIntent(Context context, String emailAddress) {
    try {/*from   ww w  . j  ava 2s .c  om*/
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("plain/text");
        intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { emailAddress });
        context.startActivity(intent);
    } catch (Exception ex) {
        Log.e(TAG, "Error starting email intent.", ex);
        Toast.makeText(context, "Sorry, we couldn't find any app for sending emails!", Toast.LENGTH_SHORT)
                .show();
    }
}