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:com.almarsoft.GroundhogReader.MessageActivity.java

private void forwardMessage() {
    String forwardMsg = "\n\n\nForwarded message originally written by "
            + mHeader.getField("From").getBody().trim() + " on the newsgroup [" + mGroup + "]: \n\n"
            + mOriginalText;/*  ww  w. j av  a  2 s . c o  m*/

    Intent i = new Intent(Intent.ACTION_SEND);
    i.putExtra(Intent.EXTRA_TEXT, forwardMsg);
    i.putExtra(Intent.EXTRA_SUBJECT, "FWD: " + mSubjectText);
    i.setType("message/rfc822");
    startActivity(Intent.createChooser(i, "Title:"));
}

From source file:com.anjalimacwan.fragment.NoteEditFragment.java

public void dispatchKeyShortcutEvent(int keyCode) {
    switch (keyCode) {

    // CTRL+S: Save
    case KeyEvent.KEYCODE_S:
        // Set current note contents to a String
        contents = noteContents.getText().toString();

        // If EditText is empty, show toast informing user to enter some text
        if (contents.equals(""))
            showToast(R.string.empty_note);
        else {//from  ww  w . j  ava2 s .  c  o m
            try {
                // Keyboard shortcut just saves the note; no dialog shown
                saveNote();
                isSavedNote = true;

                // Change window title
                String title;
                try {
                    title = listener.loadNoteTitle(filename);
                } catch (IOException e) {
                    title = getResources().getString(R.string.edit_note);
                }

                getActivity().setTitle(title);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title,
                            null, ContextCompat.getColor(getActivity(), R.color.primary));
                    getActivity().setTaskDescription(taskDescription);
                }
            } catch (IOException e) {
                // Show error message as toast if file fails to save
                showToast(R.string.failed_to_save);
            }
        }
        break;

    // CTRL+D: Delete
    case KeyEvent.KEYCODE_D:
        listener.showDeleteDialog();
        break;

    // CTRL+H: Share
    case KeyEvent.KEYCODE_H:
        // Set current note contents to a String
        contents = noteContents.getText().toString();

        // If EditText is empty, show toast informing user to enter some text
        if (contents.equals(""))
            showToast(R.string.empty_note);
        else {
            // Send a share intent
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, contents);
            shareIntent.setType("text/plain");

            // Verify that the intent will resolve to an activity, and send
            if (shareIntent.resolveActivity(getActivity().getPackageManager()) != null)
                startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
        }
        break;
    }
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
    case R.id.share:
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = "Check out " + getResources().getString(R.string.theme_name) + " by "
                + getResources().getString(R.string.nicholas_short) + "!\n\nDownload it here!: "
                + getResources().getString(R.string.play_store_link);
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title))));
        break;/*from  w ww.j  ava  2 s. c  o  m*/

    case R.id.sendemail:
        StringBuilder emailBuilder = new StringBuilder();
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
        if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
            if (!isAppInstalled("com.cyngn.theme.chooser")) {
                if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject));
                } else {
                    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_rro));
                }
            } else {
                intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cos));
            }
        } else {
            intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cm));
        }
        emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "("
                + Build.VERSION.INCREMENTAL + ")");
        emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " (" + Build.VERSION.RELEASE + ") "
                + "[" + Build.ID + "]");
        emailBuilder.append("\nDevice: " + Build.DEVICE);
        emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
        emailBuilder.append("\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")");
        if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
            if (!isAppInstalled("com.cyngn.theme.chooser")) {
                if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                    emailBuilder.append("\nTheme Engine: Not Available");
                } else {
                    emailBuilder.append("\nTheme Engine: Layers Manager (RRO)");
                }
            } else {
                emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine");
            }
        } else {
            emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine");
        }
        PackageInfo appInfo = null;
        try {
            appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        emailBuilder.append("\nApp Version Name: " + appInfo.versionName);
        emailBuilder.append("\nApp Version Code: " + appInfo.versionCode);

        intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
        startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title))));
        break;

    case R.id.changelog:
        changelog();
        break;

    case R.id.hide_launcher:
        boolean checked = item.isChecked();
        if (!checked) {
            new MaterialDialog.Builder(this).title(R.string.warning).content(R.string.hide_action)
                    .positiveText(R.string.nice).show();
        }
        item.setChecked(!checked);
        setLauncherIconEnabled(checked);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private boolean sendEmail(String body, String subject, String userEmail) {
    userEmail = findAccount(userEmail);/*from  ww w .  j  a v a2s . co  m*/
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String aEmailList[] = { userEmail };
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    emailIntent.setType("plain/text");
    try {
        startActivity(emailIntent);
        return true;
    } catch (ActivityNotFoundException anf) {
        Log.i(PacoConstants.TAG, "No email client configured");
        return false;
    }
}

From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java

public void shareImage() {

    String path = Environment.getExternalStorageDirectory().toString();
    File file = new File(path, "/" + TEMP_WALLPAPER_DIR + "/" + TEMP_WALLPAPER_NAME + ".png");

    Uri imageUri = Uri.fromFile(file);/*w ww .ja  v  a  2s. c om*/
    if (file.exists()) {
        ;
        Log.e("FILE - ", file.getAbsolutePath());
    } else {
        Log.e("ERROR - ", file.getAbsolutePath());
    }

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "Mood Wallpaper");
    intent.putExtra(Intent.EXTRA_STREAM, imageUri);
    intent.setType("image/*");
    startActivity(intent);
}

From source file:com.boko.vimusic.ui.activities.AudioPlayerActivity.java

/**
 * /** Used to shared what the user is currently listening to
 *//*from   w ww  . j  a v a  2  s.  co m*/
private void shareCurrentTrack() {
    if (MusicUtils.getTrackName() == null || MusicUtils.getArtistName() == null) {
        return;
    }
    final Intent shareIntent = new Intent();
    final String shareMessage = getString(R.string.now_listening_to, MusicUtils.getTrackName(),
            MusicUtils.getArtistName());

    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_track_using)));
}

From source file:com.aimfire.main.MainActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"/*from   w ww .  j a va 2  s. c  o  m*/
 *
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 *
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page.
 *
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first
 * then paste the link
 */
private void inviteFriend() {
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_INVITE, null);

    Resources resources = getResources();

    /*
     * construct link
     */
    String appLink = resources.getString(R.string.app_store_link);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    emailSubject = resources.getString(R.string.emailSubjectInviteFriend);
    emailText = resources.getString(R.string.emailBodyInviteFriend) + appLink;
    twitterText = resources.getString(R.string.emailBodyInviteFriend) + appLink + ", "
            + resources.getString(R.string.app_hashtag);

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 *
                 * Warning: Facebook IGNORES our text. They say "These fields are intended
                 * for users to express themselves. Pre-filling these fields erodes the
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't
                 * allow the user to choose how they want to share. We can also make a
                 * custom landing page, and the link will show the <meta content ="...">
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

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

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(appLink));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

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

From source file:net.bluecarrot.lite.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
    case R.id.top: {//scroll on the top of the page
        webViewFacebook.scrollTo(0, 0);/*from  ww  w  . j av  a 2 s.  com*/
        break;
    }
    case R.id.openInBrowser: {//open the actual page into using the browser
        webViewFacebook.getContext()
                .startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webViewFacebook.getUrl())));
        break;
    }
    case R.id.refresh: {//refresh the page
        refreshPage();
        break;
    }
    case R.id.home: {//go to the home
        goHome();
        break;
    }
    case R.id.share: {//share this app
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.downloadThisApp));
        startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share)));

        Toast.makeText(getApplicationContext(), getResources().getString(R.string.thanks), Toast.LENGTH_SHORT)
                .show();
        break;
    }
    case R.id.settings: {//open settings
        startActivity(new Intent(this, ShowSettingsActivity.class));
        return true;
    }

    case R.id.exit: {//open settings
        android.os.Process.killProcess(Process.myPid());
        System.exit(1);
        return true;
    }

    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.gpstest.GpsTestActivity.java

private void sendLocation() {
    if (mLastLocation != null) {
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "", null));
        String location = "http://maps.google.com/maps?geocode=&q="
                + Double.toString(mLastLocation.getLatitude()) + ","
                + Double.toString(mLastLocation.getLongitude());
        intent.putExtra(Intent.EXTRA_TEXT, location);
        startActivity(intent);/*ww w  .j  ava2  s.  c om*/
    }
}

From source file:com.flipzu.flipzu.Player.java

private void shareFlipzu() {

    //create the intent  
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);

    //set the type  
    shareIntent.setType("text/plain");

    //add a subject  
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this cool App");

    //build the body of the message to be shared  
    String shareMessage = "Flipzu, live audio broadcast from your Android phone: https://market.android.com/details?id="
            + APP_PNAME;// w  w w  . j av  a2  s .  c  om

    //add the message  
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage);

    //start the chooser for sharing  
    startActivity(Intent.createChooser(shareIntent, getText(R.string.share_app)));

}