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.codetroopers.shakemytours.ui.activity.TripActivity.java

private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    List<String> names = Lists.newArrayList();
    for (Travel travel : mTravels) {
        names.add(travel.name);/*from w  w  w  . jav a2 s  . c o  m*/
    }

    String textToShare = "This is a great shake (" + Strings.join("->", names) + "), SHAKE it out !";
    shareIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
    return shareIntent;
}

From source file:com.digipom.manteresting.android.fragment.NailFragment.java

private boolean handleMenuItemSelected(int listItemPosition, int itemId) {
    listItemPosition -= listView.getHeaderViewsCount();

    if (listItemPosition >= 0 && listItemPosition < nailAdapter.getCount()) {
        switch (itemId) {
        case R.id.share:
            try {
                final Cursor cursor = (Cursor) nailAdapter.getItem(listItemPosition);

                if (cursor != null && !cursor.isClosed()) {
                    final int nailId = cursor.getInt(cursor.getColumnIndex(Nails.NAIL_ID));
                    final JSONObject nailJson = new JSONObject(
                            cursor.getString(cursor.getColumnIndex(Nails.NAIL_JSON)));

                    final Uri uri = MANTERESTING_SERVER.buildUpon().appendPath("nail")
                            .appendPath(String.valueOf(nailId)).build();
                    String description = nailJson.getString("description");

                    if (description.length() > 100) {
                        description = description.substring(0, 97) + '';
                    }/*from   w w  w.jav  a2  s  . co  m*/

                    final String user = nailJson.getJSONObject("user").getString("username");
                    final String category = nailJson.getJSONObject("workbench").getJSONObject("category")
                            .getString("title");

                    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, description + ' ' + uri.toString());
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT,
                            String.format(getResources().getString(R.string.shareSubject), user, category));
                    try {
                        startActivity(Intent.createChooser(shareIntent, getText(R.string.share)));
                    } catch (ActivityNotFoundException e) {
                        new AlertDialog.Builder(getActivity()).setMessage(R.string.noShareApp).show();
                    }
                }
            } catch (Exception e) {
                if (LoggerConfig.canLog(Log.WARN)) {
                    Log.w(TAG, "Could not share nail at position " + listItemPosition + " with id " + itemId);
                }
            }

            return true;
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.xorcode.andtweet.TweetListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    super.onContextItemSelected(item);
    AdapterView.AdapterContextMenuInfo info;
    try {//from w ww .  ja  va2  s  .  c om
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }

    mCurrentId = info.id;

    Uri uri;
    Cursor c;

    switch (item.getItemId()) {
    case CONTEXT_MENU_ITEM_REPLY:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID }, null, null, null);
        try {
            c.moveToFirst();
            String reply = "@" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " ";
            long replyId = c.getLong(c.getColumnIndex(Tweets._ID));
            mTweetEditor.startEditing(reply, replyId);
        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_RETWEET:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null,
                null, null);
        try {
            c.moveToFirst();

            StringBuilder message = new StringBuilder();
            String reply = "RT @" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " ";
            message.append(reply);
            CharSequence text = c.getString(c.getColumnIndex(Tweets.MESSAGE));
            int len = 140 - reply.length() - 3;
            if (text.length() < len) {
                len = text.length();
            }
            message.append(text, 0, len);
            if (message.length() == 137) {
                message.append("...");
            }
            mTweetEditor.startEditing(message.toString(), 0);
        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_DESTROY_STATUS:
        sendCommand(new CommandData(CommandEnum.DESTROY_STATUS, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_FAVORITE:
        sendCommand(new CommandData(CommandEnum.CREATE_FAVORITE, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_DESTROY_FAVORITE:
        sendCommand(new CommandData(CommandEnum.DESTROY_FAVORITE, mCurrentId));
        return true;

    case CONTEXT_MENU_ITEM_SHARE:
        uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
        c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null,
                null, null);
        try {
            c.moveToFirst();

            StringBuilder subject = new StringBuilder();
            StringBuilder text = new StringBuilder();
            String message = c.getString(c.getColumnIndex(Tweets.MESSAGE));

            subject.append(getText(R.string.button_create_tweet));
            subject.append(" - " + message);
            int maxlength = 80;
            if (subject.length() > maxlength) {
                subject.setLength(maxlength);
                // Truncate at the last space
                subject.setLength(subject.lastIndexOf(" "));
                subject.append("...");
            }

            text.append(message);
            text.append("\n-- \n" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)));
            text.append("\n URL: " + "http://twitter.com/" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID))
                    + "/status/" + c.getString(c.getColumnIndex(Tweets._ID)));

            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("text/plain");
            share.putExtra(Intent.EXTRA_SUBJECT, subject.toString());
            share.putExtra(Intent.EXTRA_TEXT, text.toString());
            startActivity(Intent.createChooser(share, getText(R.string.menu_item_share)));

        } catch (Exception e) {
            Log.e(TAG, "onContextItemSelected: " + e.toString());
            return false;
        } finally {
            if (c != null && !c.isClosed())
                c.close();
        }
        return true;

    case CONTEXT_MENU_ITEM_UNFOLLOW:
    case CONTEXT_MENU_ITEM_BLOCK:
    case CONTEXT_MENU_ITEM_DIRECT_MESSAGE:
    case CONTEXT_MENU_ITEM_PROFILE:
        Toast.makeText(this, R.string.unimplemented, Toast.LENGTH_SHORT).show();
        return true;
    }
    return false;
}

From source file:com.juick.android.MessageMenu.java

private void actionShareMessage() {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, listSelectedItem.toString());
    activity.startActivity(intent);/*from w w  w.ja  v a  2s  .c  o m*/
}

From source file:com.irccloud.android.activity.ImageViewerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_imageviewer, menu);

    if (getIntent() != null && getIntent().getDataString() != null) {
        Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http")));
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http"));
        intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
        intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);

        MenuItem shareItem = menu.findItem(R.id.action_share);
        ShareActionProviderHax share = (ShareActionProviderHax) MenuItemCompat.getActionProvider(shareItem);
        share.onShareActionProviderSubVisibilityChangedListener = this;
        share.setShareIntent(intent);/*w ww  .ja v  a 2s  .co  m*/
    }
    return true;
}

From source file:aerizostudios.com.cropshop.MainActivity.java

public void share_whatsapp(View v) {
    try {//from  ww  w .j  av a 2  s  .c  o  m
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.setPackage("com.whatsapp");
        i.putExtra(Intent.EXTRA_SUBJECT, "CROP SHOP");
        String sAux = "\nHey friends, Check out this COOL APP - CropShop - No Crop for Whatsapp and"
                + " Instagram. This app helps you post images on Whatsapp and Instagram without any need "
                + "of cropping them. It also adds Blur Effect to the Photos like Iphone and also"
                + " Instagram filters." + "This app allows you to share the photos"
                + " directly to Instagram,Facebook and Whatsapp from the App.\n"
                + "Download this app from the play store.\n";
        sAux = sAux + "https://play.google.com/store/apps/details?id=aerizostudios.com.cropshop \n\n";
        i.putExtra(Intent.EXTRA_TEXT, sAux);
        startActivity(i);
    } catch (Exception e) {
        Intent check = new Intent(Intent.ACTION_VIEW);
        check.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        check.setData(Uri.parse("market://details?id=" + "com.whatsapp"));
        startActivity(check);
    }
}

From source file:com.kuacm.expo2013.ui.SessionDetailActivity.java

/** Handle "share" title-bar action. */
public void onShareClick(View v) {
    // TODO: consider bringing in shortlink to session
    final String shareString = getString(R.string.share_template, mTitleString);

    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, shareString);

    startActivity(Intent.createChooser(intent, getText(R.string.title_share)));
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

public void shareComicLink() {
    Intent intent = new Intent(Intent.ACTION_SEND, null);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, getCurrentComicUrl());
    startActivity(Intent.createChooser(intent, "Share Link..."));
}

From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java

/** Handle "share" title-bar action. */
public void onShareClick(View v) {
    // TODO: consider bringing in shortlink to session
    final String shareString = getString(R.string.share_template, mTitleString, mHashtag);

    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, shareString);

    startActivity(Intent.createChooser(intent, getText(R.string.title_share)));
}

From source file:com.fa.imaged.activity.DetailActivityV2.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.detail_like:
        if (detailImageLoaderv2.user_has_liked) {
            HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, false, 0);
            liker.execute();/*from w  ww  .j  av a  2 s. c o m*/
            try {
                detailImageLoaderv2 = liker.get();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (!detailImageLoaderv2.user_has_liked) {
                Drawable myIcon = getResources().getDrawable(R.drawable.ic_like);
                myIcon.setColorFilter(0, PorterDuff.Mode.SRC_ATOP);
                detailLikeStatus.setImageDrawable(myIcon);
            }
            detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count));
        } else {
            animatePhotoLike();
            HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, true, 0);
            liker.execute();
            try {
                detailImageLoaderv2 = liker.get();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ExecutionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (detailImageLoaderv2.user_has_liked) {
                Drawable myIcon = getResources().getDrawable(R.drawable.ic_like);
                myIcon.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
                detailLikeStatus.setImageDrawable(myIcon);
            }
            detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count));

        }
        break;
    case R.id.detail_likeCounts:
        Intent i = new Intent(getBaseContext(), LikersActivity.class);
        i.putExtra("media_id", detailImageLoaderv2.id);
        i.putExtra("title", "Likers " + "(" + detailImageLoaderv2.liker_count + ")");
        startActivity(i);
        break;
    case R.id.detail_share:
        Intent shareIntent = new Intent();
        Uri uri = null;

        // Create share intent as described above
        if (!detailImageLoaderv2.video) {
            Drawable mDrawable = detailImageV2.getDrawable();
            Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap();
            String path = Images.Media.insertImage(getContentResolver(), mBitmap, detailImageLoaderv2.full_name,
                    detailImageLoaderv2.caption);
            uri = Uri.parse(path);
        } else {

        }
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.putExtra(Intent.EXTRA_TEXT, detailImageLoaderv2.caption
                + getResources().getString(R.string.share_postby) + detailImageLoaderv2.username);
        startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_to)));
        break;
    case R.id.detail_user_pic:
        viewProfile(this, detailImageLoaderv2);

    }

}