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.architjn.materialicons.ui.fragments.HomeFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == android.R.id.home) {
        drawer.openDrawer(Gravity.LEFT);
    }/* w  ww  . j a  va  2s .c  o m*/
    if (id == R.id.action_sendemail) {
        StringBuilder emailBuilder = new StringBuilder();

        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
        intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject));

        emailBuilder.append("\n \n \nOS Version: ").append(System.getProperty("os.version")).append("(")
                .append(Build.VERSION.INCREMENTAL).append(")");
        emailBuilder.append("\nOS API Level: ").append(Build.VERSION.SDK_INT);
        emailBuilder.append("\nDevice: ").append(Build.DEVICE);
        emailBuilder.append("\nManufacturer: ").append(Build.MANUFACTURER);
        emailBuilder.append("\nModel (and Product): ").append(Build.MODEL).append(" (").append(Build.PRODUCT)
                .append(")");
        PackageInfo appInfo = null;
        try {
            appInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        assert appInfo != null;
        emailBuilder.append("\nApp Version Name: ").append(appInfo.versionName);
        emailBuilder.append("\nApp Version Code: ").append(appInfo.versionCode);

        intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
        startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title))));
        return true;
    } else if (id == R.id.action_share) {
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = getResources().getString(R.string.share_one)
                + getResources().getString(R.string.developer_name)
                + getResources().getString(R.string.share_two) + MARKET_URL + getActivity().getPackageName();
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title))));
    } else if (id == R.id.action_changelog) {
        showChangelog();
    }

    return super.onOptionsItemSelected(item);
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ?Intent??//from  w  w w.ja va 2s .com
 */
public static Intent createSendTextIntent(String text) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    return intent;
}

From source file:ca.rmen.android.networkmonitor.app.log.LogActionsActivity.java

/**
 * Run the given file export, then bring up the chooser intent to share the exported file.
 *//*from w  ww  .j  a  v a2 s.c  o m*/
private void shareFile(final FileExport fileExport) {
    Log.v(TAG, "shareFile " + fileExport);
    // Use a horizontal progress bar style if we can show progress of the export.
    String dialogMessage = getString(R.string.export_progress_preparing_export);
    int dialogStyle = fileExport != null ? ProgressDialog.STYLE_HORIZONTAL : ProgressDialog.STYLE_SPINNER;
    DialogFragmentFactory.showProgressDialog(this, dialogMessage, dialogStyle, PROGRESS_DIALOG_TAG);

    AsyncTask<Void, Void, File> asyncTask = new AsyncTask<Void, Void, File>() {

        @Override
        protected File doInBackground(Void... params) {
            File file = null;
            if (fileExport != null) {
                if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
                    return null;
                try {
                    // Export the file in the background.
                    file = fileExport.export();
                } catch (Throwable t) {
                    Log.e(TAG, "Error exporting file " + fileExport + ": " + t.getMessage(), t);
                }
                if (file == null)
                    return null;
            }

            String reportSummary = SummaryExport.getSummary(LogActionsActivity.this);
            // Bring up the chooser to share the file.
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.export_subject_send_log));

            String dateRange = SummaryExport.getDataCollectionDateRange(LogActionsActivity.this);

            String messageBody = getString(R.string.export_message_text, dateRange);
            if (file != null) {
                sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
                sendIntent.setType("message/rfc822");
                messageBody += getString(R.string.export_message_text_file_attached);
            } else {
                sendIntent.setType("text/plain");
            }
            messageBody += reportSummary;
            sendIntent.putExtra(Intent.EXTRA_TEXT, messageBody);

            startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.action_share)));
            return file;
        }

        @Override
        protected void onPostExecute(File result) {
            super.onPostExecute(result);
            DialogFragment fragment = (DialogFragment) getSupportFragmentManager()
                    .findFragmentByTag(PROGRESS_DIALOG_TAG);
            if (fragment != null)
                fragment.dismissAllowingStateLoss();
            // Show a toast if we failed to export a file.
            if (fileExport != null && result == null)
                Toast.makeText(LogActionsActivity.this, R.string.export_error_sdcard_unmounted,
                        Toast.LENGTH_LONG).show();
            finish();
        }

    };
    asyncTask.execute();
}

From source file:com.atahani.telepathy.ui.fragment.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View customLayout = inflater.inflate(R.layout.fragment_about_dialog, null);
    //config app version information
    mAppPreferenceTools = new AppPreferenceTools(TApplication.applicationContext);
    AppCompatTextView txAndroidAppVerInfo = (AppCompatTextView) customLayout
            .findViewById(R.id.tx_android_ver_info);
    txAndroidAppVerInfo.setText(String.format(getString(R.string.label_telepathy_for_android),
            mAppPreferenceTools.getTheLastAppVersion()));
    txAndroidAppVerInfo.setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w  w  .j  a  va 2 s .c om*/
        public void onClick(View v) {
            try {
                //open browser to navigate telepathy website
                Uri telepathyWebSiteUri = Uri.parse("https://github.com/atahani/telepathy-android.git");
                startActivity(new Intent(Intent.ACTION_VIEW, telepathyWebSiteUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config google play store link
    AppCompatTextView txRateUsOnGooglePlayStore = (AppCompatTextView) customLayout
            .findViewById(R.id.tx_rate_us_on_play_store);
    txRateUsOnGooglePlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //navigate to market for rate application
            Uri uri = Uri.parse("market://details?id=" + TApplication.applicationContext.getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            // To count with Play market backstack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(goToMarket);
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (ActivityNotFoundException e) {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="
                                + TApplication.applicationContext.getPackageName())));
            }
        }
    });
    //config twitter link
    AppCompatTextView txTwitterLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_twitter_telepathy);
    txTwitterLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                // If Twitter app is not installed, start browser.
                Uri twitterUri = Uri.parse("http://twitter.com/");
                startActivity(new Intent(Intent.ACTION_VIEW, twitterUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config privacy link
    AppCompatTextView txPrivacyLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_privacy);
    txPrivacyLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                //open browser to navigate privacy link
                Uri privacyPolicyUri = Uri
                        .parse("https://github.com/atahani/telepathy-android/blob/master/LICENSE.md");
                startActivity(new Intent(Intent.ACTION_VIEW, privacyPolicyUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config report bug to open mail application and send bugs report
    AppCompatTextView txReportBug = (AppCompatTextView) customLayout.findViewById(R.id.tx_report_bug);
    txReportBug.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                final Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
                emailIntent.setType("plain/text");
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        getString(R.string.label_report_bug_email_subject));
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailDeviceInformation());
                emailIntent.setData(Uri.parse("mailto:" + getString(R.string.telepathy_report_bug_email)));
                startActivity(Intent.createChooser(emailIntent,
                        getString(R.string.label_report_bug_choose_mail_app)));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config the about footer image view
    AboutFooterImageView footerImageView = (AboutFooterImageView) customLayout
            .findViewById(R.id.im_delete_user_account);
    footerImageView.setTouchOnImageViewEventListener(new AboutFooterImageView.touchOnImageViewEventListener() {
        @Override
        public void onDoubleTab() {
            try {
                //confirm account delete via alert dialog
                final AlertDialog.Builder confirmAccountDeleteDialog = new AlertDialog.Builder(getActivity());
                confirmAccountDeleteDialog.setTitle(getString(R.string.label_delete_user_account));
                confirmAccountDeleteDialog
                        .setMessage(getString(R.string.label_delete_user_account_description));
                confirmAccountDeleteDialog.setNegativeButton(getString(R.string.action_no), null);
                confirmAccountDeleteDialog.setPositiveButton(getString(R.string.action_yes),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //ok to delete account action
                                final ProgressDialog progressDialog = new ProgressDialog(getActivity());
                                progressDialog.setCancelable(false);
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog
                                        .setMessage(getString(R.string.re_action_on_deleting_user_account));
                                progressDialog.show();
                                TService tService = ((TelepathyBaseActivity) getActivity()).getTService();
                                tService.deleteUserAccount(new Callback<TOperationResultModel>() {
                                    @Override
                                    public void success(TOperationResultModel tOperationResultModel,
                                            Response response) {
                                        if (getActivity() != null && isAdded()) {
                                            //broad cast to close all of the realm  instance
                                            Intent intentToCloseRealm = new Intent(
                                                    Constants.TELEPATHY_BASE_ACTIVITY_INTENT_FILTER);
                                            intentToCloseRealm.putExtra(Constants.ACTION_TO_DO_PARAM,
                                                    Constants.CLOSE_REALM_DB);
                                            LocalBroadcastManager.getInstance(getActivity())
                                                    .sendBroadcastSync(intentToCloseRealm);
                                            mAppPreferenceTools.removeAllOfThePref();
                                            //                                 for sign out google first build GoogleAPIClient
                                            final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(
                                                    TApplication.applicationContext)
                                                            .addApi(Auth.GOOGLE_SIGN_IN_API).build();
                                            googleApiClient.connect();
                                            googleApiClient.registerConnectionCallbacks(
                                                    new GoogleApiClient.ConnectionCallbacks() {
                                                        @Override
                                                        public void onConnected(Bundle bundle) {
                                                            Auth.GoogleSignInApi.signOut(googleApiClient)
                                                                    .setResultCallback(
                                                                            new ResultCallback<Status>() {
                                                                                @Override
                                                                                public void onResult(
                                                                                        Status status) {
                                                                                    //also revoke google access
                                                                                    Auth.GoogleSignInApi
                                                                                            .revokeAccess(
                                                                                                    googleApiClient)
                                                                                            .setResultCallback(
                                                                                                    new ResultCallback<Status>() {
                                                                                                        @Override
                                                                                                        public void onResult(
                                                                                                                Status status) {
                                                                                                            progressDialog
                                                                                                                    .dismiss();
                                                                                                            TelepathyBaseActivity currentActivity = (TelepathyBaseActivity) TApplication.mCurrentActivityInApplication;
                                                                                                            if (currentActivity != null) {
                                                                                                                Intent intent = new Intent(
                                                                                                                        TApplication.applicationContext,
                                                                                                                        SignInActivity.class);
                                                                                                                intent.setFlags(
                                                                                                                        Intent.FLAG_ACTIVITY_CLEAR_TASK
                                                                                                                                | Intent.FLAG_ACTIVITY_NEW_TASK);
                                                                                                                currentActivity
                                                                                                                        .startActivity(
                                                                                                                                intent);
                                                                                                                currentActivity
                                                                                                                        .setAnimationOnStart();
                                                                                                                currentActivity
                                                                                                                        .finish();
                                                                                                            }
                                                                                                        }
                                                                                                    });
                                                                                }
                                                                            });
                                                        }

                                                        @Override
                                                        public void onConnectionSuspended(int i) {
                                                            //do nothing
                                                        }
                                                    });
                                        }
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        progressDialog.dismiss();
                                        if (getActivity() != null && isAdded()) {
                                            CommonFeedBack commonFeedBack = new CommonFeedBack(
                                                    getActivity().findViewById(android.R.id.content),
                                                    getActivity());
                                            commonFeedBack.checkCommonErrorAndBackUnCommonOne(error);
                                        }
                                    }
                                });
                            }
                        });
                confirmAccountDeleteDialog.show();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    builder.setView(customLayout);
    return builder.create();
}

From source file:ca.rmen.android.poetassistant.main.reader.ReaderFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_new) {
        ConfirmDialogFragment.show(ACTION_FILE_NEW, getString(R.string.file_new_confirm_title),
                getString(R.string.action_clear), getChildFragmentManager(), DIALOG_TAG);
    } else if (item.getItemId() == R.id.action_open) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            open();//from w  ww.  ja  v  a2s.  co m
    } else if (item.getItemId() == R.id.action_save) {
        PoemFile poemFile = mPoemPrefs.getSavedPoem();
        PoemFile.save(getActivity(), poemFile.uri, mBinding.tvText.getText().toString(), this);
    } else if (item.getItemId() == R.id.action_save_as) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            saveAs();
    } else if (item.getItemId() == R.id.action_share) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, mBinding.tvText.getText().toString());
        intent.setType("text/plain");
        startActivity(Intent.createChooser(intent, getString(R.string.share)));
    }
    return true;
}

From source file:com.cmput301.recipebot.ui.AbstractRecipeActivity.java

/**
 * Creates a sharing {@link android.content.Intent}.
 * Shares mRecipe, doesn't get it from the UI.
 *
 * @return The sharing intent.//from   w  w  w.java 2s  .c  o  m
 */
private static Intent createShareIntent(Recipe recipe, File file) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, recipe.getName());
    shareIntent.putExtra(Intent.EXTRA_TITLE, recipe.getName());
    shareIntent.putExtra(Intent.EXTRA_TEXT, recipe.toEmail());
    shareIntent.setType("application/json");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    return shareIntent;
}

From source file:com.codebutler.farebot.activities.AdvancedCardInfoActivity.java

private void reportError() {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override/*from w  w  w . j  a v  a 2 s .  co m*/
        public void onClick(DialogInterface dialog, int which) {
            StringBuilder builder = new StringBuilder();
            builder.append(Utils.getDeviceInfoString());
            builder.append("\n\n");

            builder.append(mError.toString());
            builder.append("\n");
            builder.append(Utils.getErrorMessage(mError));
            builder.append("\n");
            for (StackTraceElement elem : mError.getStackTrace()) {
                builder.append(elem.toString());
                builder.append("\n");
            }

            builder.append("\n\n");

            try {
                builder.append(Utils.xmlNodeToString(mCard.toXML().getOwnerDocument()));
            } catch (Exception ex) {
                builder.append("Failed to generate XML: ");
                builder.append(ex);
            }

            builder.append("\n\n");
            builder.append(getString(R.string.comments));
            builder.append(":\n\n");

            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:eric+farebot@codebutler.com"));
            intent.putExtra(Intent.EXTRA_SUBJECT, "FareBot Bug Report");
            intent.putExtra(Intent.EXTRA_TEXT, builder.toString());
            startActivity(intent);

        }
    };
    new AlertDialog.Builder(this).setTitle(R.string.report_error_privacy_title)
            .setMessage(R.string.report_error_privacy_message).setPositiveButton(android.R.string.ok, listener)
            .setNegativeButton(android.R.string.cancel, null).show();
}

From source file:au.com.wallaceit.reddinator.ViewRedditActivity.java

public void shareText(String txt) {
    Intent sendintent = new Intent(Intent.ACTION_SEND);
    sendintent.setAction(Intent.ACTION_SEND);
    sendintent.putExtra(Intent.EXTRA_TEXT, txt);
    sendintent.setType("text/plain");
    startActivity(Intent.createChooser(sendintent, "Share Url to..."));
}

From source file:com.code.android.vibevault.FeaturedShowsScreen.java

/** Handle user's long-click selection.
*
*//*  w ww.jav a 2  s  .c  om*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo != null) {
        ArchiveShowObj selShow = (ArchiveShowObj) featuredShowsList.getAdapter().getItem(menuInfo.position);
        switch (item.getItemId()) {
        case VibeVault.EMAIL_LINK:
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Great show on archive.org: " + selShow.getArtistAndTitle());
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    "Hey,\n\nYou should listen to " + selShow.getArtistAndTitle() + ".  You can find it here: "
                            + selShow.getShowURL() + "\n\nSent using VibeVault for Android.");
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            return true;
        case (VibeVault.ADD_TO_FAVORITE_LIST):
            VibeVault.db.insertFavoriteShow(selShow);
            return true;
        default:
            break;
        }
        return false;
    }
    return true;
}

From source file:gov.wa.wsdot.android.wsdot.ui.TwitterFragment.java

private Intent createShareIntent(String mText) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mText);

    return shareIntent;
}