Example usage for android.content Intent ACTION_SEND

List of usage examples for android.content Intent ACTION_SEND

Introduction

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

Prototype

String ACTION_SEND

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

Click Source Link

Document

Activity Action: Deliver some data to someone else.

Usage

From source file:com.wellsandwhistles.android.redditsp.reddit.api.RedditAPICommentAction.java

public static void onActionMenuItemSelected(final RedditRenderableComment renderableComment,
        final RedditCommentView commentView, final AppCompatActivity activity,
        final CommentListingFragment commentListingFragment, final RedditCommentAction action,
        final RedditChangeDataManager changeDataManager) {

    final RedditComment comment = renderableComment.getParsedComment().getRawComment();

    switch (action) {

    case UPVOTE:// w  w  w  . ja va  2s  . co  m
        action(activity, comment, RedditAPI.ACTION_UPVOTE, changeDataManager);
        break;

    case DOWNVOTE:
        action(activity, comment, RedditAPI.ACTION_DOWNVOTE, changeDataManager);
        break;

    case UNVOTE:
        action(activity, comment, RedditAPI.ACTION_UNVOTE, changeDataManager);
        break;

    case SAVE:
        action(activity, comment, RedditAPI.ACTION_SAVE, changeDataManager);
        break;

    case UNSAVE:
        action(activity, comment, RedditAPI.ACTION_UNSAVE, changeDataManager);
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_REPORT, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, comment.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY,
                StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(activity, CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.getIdAndType());
        intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case DELETE: {
        new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm)
                .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_DELETE, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        break;
    }

    case COMMENT_LINKS:
        final HashSet<String> linksInComment = comment.computeAllLinks();

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_comment);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_comment_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;

    case SHARE:

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.body) + "\r\n\r\n"
                + comment.getContextUrl().generateNonJsonUri().toString());

        activity.startActivityForResult(Intent.createChooser(mailer, activity.getString(R.string.action_share)),
                1);

        break;

    case COPY_TEXT: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.body));
        break;
    }

    case COPY_URL: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(comment.getContextUrl().context(null).generateNonJsonUri().toString());
        break;
    }

    case COLLAPSE: {
        commentListingFragment.handleCommentVisibilityToggle(commentView);
        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(comment.author).toString());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment).show(activity.getSupportFragmentManager(), null);
        break;

    case GO_TO_COMMENT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().context(null).toString());
        break;
    }

    case CONTEXT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().toString());
        break;
    }
    case ACTION_MENU:
        showActionMenu(activity, commentListingFragment, renderableComment, commentView, changeDataManager,
                comment.isArchived());
        break;

    case BACK:
        activity.onBackPressed();
        break;
    }
}

From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // handle item selection
    final Activity activity = getActivity();
    switch (item.getItemId()) {
    case R.id.action_download:
        Toast.makeText(activity,//from   w  ww .java2  s . co m
                String.format(getActivity().getResources().getString(R.string.toast_downloading), urls.size()),
                Toast.LENGTH_SHORT).show();
        Intent serviceIntent = new Intent(activity, DownloadService.class);
        serviceIntent.putParcelableArrayListExtra("ids", ids);
        if (albumId != null)
            serviceIntent.putExtra("albumName", albumId);
        else
            serviceIntent.putExtra("albumName", imageCall);
        activity.startService(serviceIntent);
        return true;
    case R.id.action_refresh:
        urls = new ArrayList<String>();
        ids = new ArrayList<JSONParcelable>();
        page = 0;
        makeGallery();
        return true;
    case R.id.action_copy:
        ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("imgur Link", "http://imgur.com/a/" + albumId);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(activity, R.string.toast_copied, Toast.LENGTH_SHORT).show();
        return true;
    case R.id.action_share:
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        intent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + albumId);
        startActivity(intent);
        return true;
    case R.id.action_new:
        Intent i = new Intent(this.getActivity().getApplicationContext(), ImageSelectActivity.class);
        startActivityForResult(i, 1);
        //select image
        return true;
    case R.id.action_comments:
        if (galleryAlbumData != null) {
            CommentsAsync commentsAsync = new CommentsAsync(((ImgurHoloActivity) getActivity()),
                    galleryAlbumData);
            commentsAsync.execute();
            return true;
        } else
            return super.onOptionsItemSelected(item);
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:key.secretkey.crypto.PgpHandler.java

public void shareAsPlaintext() {

    if (findViewById(R.id.share_password_as_plaintext) == null)
        return;//  w  ww . j ava 2  s  .  c om

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, decodedPassword);
    sendIntent.setType("text/plain");
    startActivity(
            Intent.createChooser(sendIntent, getResources().getText(R.string.send_plaintext_password_to)));//Always show a picker to give the user a chance to cancel
}

From source file:com.game.simple.Game3.java

public static void sendEmail(String address, String subject, String content) {
    //---timer---//
    //StartReConnect();
    //-----------//
    String[] _address = { address.toString() };
    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, _address);
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, content);
    email.setType("message/rfc822");
    self.startActivity(Intent.createChooser(email, "Choose an Email client :"));

}

From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java

/** Called when a session detail view asks to send session results somewhere. 
 * Generates a link to the session report Uri, and lets the remote program read from it. 
 * The {@link RhetologContentProvider} generates the result file on demand.
 * //from  ww w  . j a va2 s.  c om
 * */

@Override
public void onSessionSend(Context context, Uri session) {

    // Send to the program selected by the chooser below.
    Intent sendSession = new Intent(Intent.ACTION_SEND);

    // Permit to read from Rhetolog URIs.
    sendSession.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    // Note type of send as report.
    sendSession.setType(RhetologContract.RHETOLOG_TYPE_SESSION_REPORT);

    sendSession.putExtra(Intent.EXTRA_SUBJECT, "Sending session " + session);

    // Send text as text.
    sendSession.putExtra(Intent.EXTRA_TEXT, reportForSession(session));

    // Send text as URI to be read.
    sendSession.putExtra(Intent.EXTRA_STREAM,
            Uri.parse(RhetologContract.SESSIONSREPORT + "/" + session.getLastPathSegment()));

    // Permit user to choose target of send.
    context.startActivity(Intent.createChooser(sendSession, "Send session results"));
}

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

/** Handle user's long-click selection.
*
*///from   w  ww.j a  v a  2  s .c om
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo != null) {
        ArchiveShowObj selShow = (ArchiveShowObj) searchList.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.SHOW_INFO:
            AlertDialog.Builder ad = new AlertDialog.Builder(this);
            ad.setTitle("Show Info");
            View v = LayoutInflater.from(this).inflate(R.layout.scrollable_dialog, null);
            ((TextView) v.findViewById(R.id.DialogText)).setText(selShow.getSource());
            ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                }
            });
            ad.setView(v);
            ad.show();
            return true;
        case (VibeVault.ADD_TO_FAVORITE_LIST):
            VibeVault.db.insertFavoriteShow(selShow);
            return true;
        default:
            return false;
        }
    }
    return false;
}

From source file:fr.simon.marquis.secretcodes.ui.MainActivity.java

private void sendEmail(ArrayList<SecretCode> secretCodes) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { getString(R.string.extra_email) });
    i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.extra_subject));
    i.putExtra(Intent.EXTRA_TEXT, generateEmailBody(secretCodes));
    i.putExtra(Intent.EXTRA_STREAM, ExportContentProvider.CONTENT_URI);
    startActivity(Intent.createChooser(i, null));
}

From source file:com.actionbarsherlock.sample.hcgallery.ContentFragment.java

void shareCurrentPhoto() {
    File externalCacheDir = getActivity().getExternalCacheDir();
    if (externalCacheDir == null) {
        Toast.makeText(getActivity(), "Error writing to USB/external storage.", Toast.LENGTH_SHORT).show();
        return;/*from  ww w .j a va2 s . co  m*/
    }

    // Prevent media scanning of the cache directory.
    final File noMediaFile = new File(externalCacheDir, ".nomedia");
    try {
        noMediaFile.createNewFile();
    } catch (IOException e) {
    }

    // Write the bitmap to temporary storage in the external storage directory (e.g. SD card).
    // We perform the actual disk write operations on a separate thread using the
    // {@link AsyncTask} class, thus avoiding the possibility of stalling the main (UI) thread.

    final File tempFile = new File(externalCacheDir, "tempfile.jpg");

    new AsyncTask<Void, Void, Boolean>() {
        /**
         * Compress and write the bitmap to disk on a separate thread.
         * @return TRUE if the write was successful, FALSE otherwise.
         */
        protected Boolean doInBackground(Void... voids) {
            try {
                FileOutputStream fo = new FileOutputStream(tempFile, false);
                if (!mBitmap.compress(Bitmap.CompressFormat.JPEG, 60, fo)) {
                    Toast.makeText(getActivity(), "Error writing bitmap data.", Toast.LENGTH_SHORT).show();
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;

            } catch (FileNotFoundException e) {
                Toast.makeText(getActivity(), "Error writing to USB/external storage.", Toast.LENGTH_SHORT)
                        .show();
                return Boolean.FALSE;
            }
        }

        /**
         * After doInBackground completes (either successfully or in failure), we invoke an
         * intent to share the photo. This code is run on the main (UI) thread.
         */
        protected void onPostExecute(Boolean result) {
            if (result != Boolean.TRUE) {
                return;
            }

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));
            shareIntent.setType("image/jpeg");
            startActivity(Intent.createChooser(shareIntent, "Share photo"));
        }
    }.execute();
}

From source file:com.eyekabob.util.EyekabobHelper.java

public static void launchEmail(Activity activity) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    String to[] = { "philj21@yahoo.com", "adam.sill01@gmail.com", "coffbr01@gmail.com" };
    emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Eyekabob Advertising");
    String label = activity.getResources().getString(R.string.write_email);
    activity.startActivity(Intent.createChooser(emailIntent, label));
}

From source file:barqsoft.footballscores.Fragments.DetailFragment.java

public Intent createShareForecastIntent(String ShareText) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, ShareText + getString(R.string.football_scores_hashtag));
    return shareIntent;
}