Example usage for android.content Intent EXTRA_TEXT

List of usage examples for android.content Intent EXTRA_TEXT

Introduction

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

Prototype

String EXTRA_TEXT

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

Click Source Link

Document

A constant CharSequence that is associated with the Intent, used with #ACTION_SEND to supply the literal data to be sent.

Usage

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);/* w  w w.  jav a2 s .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 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);//from   w  ww. jav  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 shareText(Context context, String title, String text) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(intent, title));
}

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);
            }//from  w  w w.j  a va  2 s.  c  o m

            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 void shareText(Context ctx, String title, String text) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    //intent.putExtra(Intent.EXTRA_SUBJECT, title);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    ctx.startActivity(Intent.createChooser(intent, title));
    /* List<ResolveInfo> ris = getShareTargets(ctx);
     if (ris != null && ris.size() > 0) {
     ctx.startActivity(Intent.createChooser(intent, title));
     }*//* w  w  w  . jav  a  2 s. co m*/
}

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 shareOnTwitter(Context pContext, String urlToShare) {

    Intent tweetIntent = new Intent(Intent.ACTION_SEND);
    tweetIntent.putExtra(Intent.EXTRA_TEXT, urlToShare);
    tweetIntent.setType("text/plain");

    PackageManager packManager = pContext.getPackageManager();
    List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,
            PackageManager.MATCH_DEFAULT_ONLY);

    boolean resolved = false;
    for (ResolveInfo resolveInfo : resolvedInfoList) {
        if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
            tweetIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
            resolved = true;/*w w  w  .j a  v  a2s .  c  o  m*/
            break;
        }
    }
    if (resolved) {
        pContext.startActivity(tweetIntent);
    } else {
        Intent i = new Intent();
        i.putExtra(Intent.EXTRA_TEXT, urlToShare);
        i.setAction(Intent.ACTION_VIEW);
        i.setData(Uri.parse("https://twitter.com/intent/tweet?text=message&via=profileName"));
        pContext.startActivity(i);
    }
}

From source file:Main.java

public static void callSysShare(Context context, String chooserTitle, String shareTitle, String shareText,
        String mime, Uri uri) {/*from w w w .  j  ava  2s .co m*/
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Intent.EXTRA_TEXT, shareText);
    intent.putExtra(Intent.EXTRA_SUBJECT, shareTitle);
    intent.setType(mime);
    if (uri != null) {
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    }
    context.startActivity(Intent.createChooser(intent, chooserTitle));
}

From source file:Main.java

/**
 * Easily create email intent//from ww w . j a  v a 2 s. c o 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;
}