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.saulcintero.moveon.fragments.History.java

public static void sendAction(final Activity act, int[] idList, String[] nameList, String[] activityList,
        String[] shortDescriptionList, String[] longDescriptionList) {
    ArrayList<Integer> positions = new ArrayList<Integer>();
    for (int p = 0; p < idList.length; p++) {
        String nameToSearch = osmFilesNameFromUploadPosition.get(p).substring(0,
                osmFilesNameFromUploadPosition.get(p).length() - 4);
        positions.add(ArrayUtils.indexOf(listOfFiles, nameToSearch));
    }/*from www. j av  a  2 s  . com*/

    for (int j = 0; j < idList.length; j++) {
        final String name = nameList[j];
        final String activity = activityList[j];
        final String shortDescription = shortDescriptionList[j];
        final String longDescription = longDescriptionList[j];
        final String url = osmUrlsToShare.get(positions.get(j));
        Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        List<ResolveInfo> activities = act.getPackageManager().queryIntentActivities(sendIntent, 0);
        AlertDialog.Builder builder = new AlertDialog.Builder(act);
        builder.setTitle(act.getText(R.string.send_to) + " " + name + " " + act.getText(R.string.share_with));
        final ShareIntentListAdapter adapter = new ShareIntentListAdapter(act, R.layout.social_share,
                activities.toArray());
        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ResolveInfo info = (ResolveInfo) adapter.getItem(which);
                if (info.activityInfo.packageName.contains("facebook")) {
                    Intent i = new Intent("android.intent.action.PUBLISH_TO_FB_WALL");
                    i.putExtra("name", activity + " " + name);
                    i.putExtra("msg", String.format("%s", shortDescription));
                    i.putExtra("link", String.format("%s", url));
                    act.sendBroadcast(i);
                } else {
                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                    intent.setType("text/plain");
                    if ((info.activityInfo.packageName.contains("twitter"))
                            || (info.activityInfo.packageName.contains("sms"))
                            || (info.activityInfo.packageName.contains("mms"))) {
                        intent.putExtra(Intent.EXTRA_TEXT, shortDescription + url);
                    } else {
                        intent.putExtra(Intent.EXTRA_TEXT, longDescription + url);
                    }
                    act.startActivity(intent);
                }
            }
        });
        builder.create().show();
    }
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static Intent createStatusShareIntent(final Context context, final ParcelableStatus status) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    final String name = status.user_name, screenName = status.user_screen_name;
    final String timeString = formatToLongTimeString(context, status.timestamp);
    final String subject = context.getString(R.string.share_subject_format, name, screenName, timeString);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, status.text_plain);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    return intent;
}

From source file:com.android.contacts.activities.PeopleActivity.java

/**
 * Share all contacts that are currently selected in mAllFragment. This method is pretty
 * inefficient for handling large numbers of contacts. I don't expect this to be a problem.
 *//*from  w w  w .j  a v a 2 s  .  co m*/
private void shareSelectedContacts() {
    final StringBuilder uriListBuilder = new StringBuilder();
    for (Long contactId : mAllFragment.getSelectedContactIds()) {
        final Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
        final Uri lookupUri = Contacts.getLookupUri(getContentResolver(), contactUri);
        if (lookupUri == null) {
            continue;
        }
        final List<String> pathSegments = lookupUri.getPathSegments();
        if (pathSegments.size() < 2) {
            continue;
        }
        final String lookupKey = pathSegments.get(pathSegments.size() - 2);
        if (uriListBuilder.length() > 0) {
            uriListBuilder.append(':');
        }
        uriListBuilder.append(Uri.encode(lookupKey));
    }
    if (uriListBuilder.length() == 0) {
        return;
    }
    final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_MULTI_VCARD_URI,
            Uri.encode(uriListBuilder.toString()));
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType(Contacts.CONTENT_VCARD_TYPE);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    ImplicitIntentsUtil.startActivityOutsideApp(this, intent);
}

From source file:com.androzic.MapFragment.java

@Override
public boolean onMenuItemSelected(MenuBuilder builder, MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_information: {
        FragmentManager manager = getFragmentManager();
        LocationInfo dialog = new LocationInfo(application.getMapCenter());
        dialog.show(manager, "dialog");
        return true;
    }/*from w  ww .  j av  a2s  .c  om*/
    case R.id.action_share: {
        Intent i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_SUBJECT, R.string.currentloc);
        double[] loc = application.getMapCenter();
        String spos = StringFormatter.coordinates(" ", loc[0], loc[1]);
        i.putExtra(Intent.EXTRA_TEXT, spos);
        startActivity(Intent.createChooser(i, getString(R.string.menu_share)));
        return true;
    }
    case R.id.action_view_elsewhere: {
        double[] sloc = application.getMapCenter();
        String geoUri = "geo:" + Double.toString(sloc[0]) + "," + Double.toString(sloc[1]);
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(geoUri));
        startActivity(intent);
        return true;
    }
    case R.id.action_copy_location: {
        double[] cloc = application.getMapCenter();
        String cpos = StringFormatter.coordinates(" ", cloc[0], cloc[1]);
        Clipboard.copy(getActivity(), cpos);
        return true;
    }
    case R.id.action_paste_location: {
        String text = Clipboard.paste(getActivity());
        try {
            double c[] = CoordinateParser.parse(text);
            if (!Double.isNaN(c[0]) && !Double.isNaN(c[1])) {
                boolean mapChanged = application.setMapCenter(c[0], c[1], true, true, false);
                if (mapChanged)
                    map.updateMapInfo();
                map.updateMapCenter();
                following = false;
                map.setFollowing(false);
            }
        } catch (IllegalArgumentException e) {
        }
        return true;
    }
    case R.id.action_add_to_route: {
        Waypoint wpt = application.getWaypoint(waypointSelected);
        application.routeEditingWaypoints
                .push(application.editingRoute.addWaypoint(wpt.name, wpt.latitude, wpt.longitude));
        refreshMap();
        return true;
    }
    case R.id.action_navigate: {
        application.navigationService.setRouteWaypoint(waypointSelected);
        return true;
    }
    case R.id.action_mapobject_navigate: {
        application.startNavigation(application.getMapObject(mapObjectSelected));
        return true;
    }
    }
    return false;
}

From source file:activities.PaintActivity.java

@Override
public void onCompartirButtonClicked() {

    final Resources resources = getResources();

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

    final List<String> listStringPackages = new ArrayList<String>();

    List<ResolveInfo> apps = pm.queryIntentActivities(sendIntent, PackageManager.MATCH_DEFAULT_ONLY);
    Iterator i = apps.iterator();
    //Aca creamos nuestro filtro de apps especificas
    while (i.hasNext()) {
        ResolveInfo app = (ResolveInfo) i.next();
        String packageName = app.activityInfo.applicationInfo.packageName;
        if (packageName.contains("facebook") || packageName.contains("twitter") || packageName.contains("gm")) {
            listStringPackages.add(packageName);
        }/*from ww w  . java 2  s .c om*/

    }

    ArrayAdapter<String> adapter = new ShareChooserAdapter(this, android.R.layout.select_dialog_item,
            android.R.id.text1, listStringPackages);

    new AlertDialog.Builder(this).setTitle(string.sharechooser_title)
            .setAdapter(adapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    invokeApplication(listStringPackages.get(i), resources);
                }
            }).setCancelable(true).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    Log.d("DialogShare", "canceled, se borra la imagen...");
                }
            }).show();

}

From source file:activities.PaintActivity.java

private void invokeApplication(String packageName, Resources resources) {

    int requestCode = 0;
    Log.d("DialogShare", "Seleccionado ... " + packageName);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.setType("image/*");

    shareIntent.setPackage(packageName);

    //Image/*  w w  w.  jav  a2s  . c o  m*/
    Bitmap bitmap = painter.getImageBitmap();

    if ((uriTempImage = PaintUtility.saveTempPhoto(this, bitmap)) == null)
        Toast.makeText(this, "Error al crear imagonen ", Toast.LENGTH_SHORT).show();

    shareIntent.putExtra(Intent.EXTRA_STREAM, uriTempImage);

    if (packageName.contains("twitter")) {
        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_twitter_text));
        requestCode = RS_CODE_SHARE_TWITTER;

    } else if (packageName.contains("facebook")) {
        // 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.
        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_fb_text));
        requestCode = RS_CODE_SHARE_FB;
    } else if (packageName.contains("gm")) {

        shareIntent.putExtra(Intent.EXTRA_TEXT, resources.getString(string.sharecontent_email_text));
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(string.sharecontent_subject));
        shareIntent.setType("message/rfc822");
        requestCode = RS_CODE_SHARE_GMAIL;
    }

    startActivityForResult(shareIntent, requestCode);
}

From source file:org.getlantern.firetweet.util.Utils.java

public static Intent createStatusShareIntent(final Context context, final ParcelableStatus status) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, getStatusShareSubject(context, status));
    intent.putExtra(Intent.EXTRA_TEXT, getStatusShareText(context, status));
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    return intent;
}

From source file:com.android.calendar.EventInfoFragment.java

/**
 * Generates an .ics formatted file with the event info and launches intent chooser to
 * share said file/*from  ww  w  .j  ava2 s.c o m*/
 */
public void shareEvent(ShareType type) {
    VCalendar calendar = generateVCalendar();
    // create and share ics file
    boolean isShareSuccessful = false;
    try {
        // event title serves as the file name prefix
        String filePrefix = calendar.getFirstEvent().getProperty(VEvent.SUMMARY);
        if (filePrefix == null || filePrefix.length() < 3) {
            // default to a generic filename if event title doesn't qualify
            // prefix length constraint is imposed by File#createTempFile
            filePrefix = "invite";
        }

        filePrefix = filePrefix.replaceAll("\\W+", " ");

        if (!filePrefix.endsWith(" ")) {
            filePrefix += " ";
        }

        File dir;
        if (type == ShareType.SDCARD) {
            dir = EXPORT_SDCARD_DIRECTORY;
            if (!dir.exists()) {
                dir.mkdir();
            }
        } else {
            dir = mActivity.getExternalCacheDir();
        }

        File inviteFile = IcalendarUtils.createTempFile(filePrefix, ".ics", dir);

        if (IcalendarUtils.writeCalendarToFile(calendar, inviteFile)) {
            if (type == ShareType.INTENT) {
                inviteFile.setReadable(true, false); // set world-readable
                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
                shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(inviteFile));
                // the ics file is sent as an extra, the receiving application decides whether
                // to parse the file to extract calendar events or treat it as a regular file
                shareIntent.setType("application/octet-stream");

                Intent chooserIntent = Intent.createChooser(shareIntent,
                        getResources().getString(R.string.cal_share_intent_title));

                // The MMS app only responds to "text/x-vcalendar" so we create a chooser intent
                // that includes the targeted mms intent + any that respond to the above general
                // purpose "application/octet-stream" intent.
                File vcsInviteFile = File.createTempFile(filePrefix, ".vcs", mActivity.getExternalCacheDir());

                // for now , we are duplicating ics file and using that as the vcs file
                // TODO: revisit above
                if (IcalendarUtils.copyFile(inviteFile, vcsInviteFile)) {
                    Intent mmsShareIntent = new Intent();
                    mmsShareIntent.setAction(Intent.ACTION_SEND);
                    mmsShareIntent.setPackage("com.android.mms");
                    mmsShareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(vcsInviteFile));
                    mmsShareIntent.setType("text/x-vcalendar");
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { mmsShareIntent });
                }
                startActivity(chooserIntent);
            } else {
                if (!mInNonUiMode) {
                    String msg = getString(R.string.cal_export_succ_msg);
                    Toast.makeText(mActivity, String.format(msg, inviteFile), Toast.LENGTH_SHORT).show();
                }
            }
            isShareSuccessful = true;

        } else {
            // error writing event info to file
            isShareSuccessful = false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        isShareSuccessful = false;
    }

    if (!isShareSuccessful) {
        Log.e(TAG, "Couldn't generate ics file");
        Toast.makeText(mActivity, R.string.error_generating_ics, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int rowId = (int) info.id;

    switch (item.getItemId()) {
    case Constants.SAVE_CONTEXT_ITEM:
        new SaveTask(true, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.UNSAVE_CONTEXT_ITEM:
        new SaveTask(false, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.HIDE_CONTEXT_ITEM:
        new HideTask(true, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.UNHIDE_CONTEXT_ITEM:
        new HideTask(false, getOpThingInfo(), mSettings, this).execute();
        return true;

    case Constants.SHARE_CONTEXT_ITEM:
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("text/plain");

        intent.putExtra(Intent.EXTRA_TEXT, getOpThingInfo().getUrl());

        try {/*from   www.j a  va2s  .co  m*/
            startActivity(Intent.createChooser(intent, "Share Link"));
        } catch (android.content.ActivityNotFoundException ex) {

        }

        return true;

    case Constants.DIALOG_HIDE_COMMENT:
        hideComment(rowId);
        return true;

    case Constants.DIALOG_SHOW_COMMENT:
        showComment(rowId);
        return true;

    case Constants.DIALOG_GOTO_PARENT:
        int myIndent = mCommentsAdapter.getItem(rowId).getIndent();
        int parentRowId;
        for (parentRowId = rowId - 1; parentRowId >= 0; parentRowId--)
            if (mCommentsAdapter.getItem(parentRowId).getIndent() < myIndent)
                break;
        getListView().setSelection(parentRowId);
        return true;

    case Constants.DIALOG_VIEW_PROFILE:
        Intent i = new Intent(this, ProfileActivity.class);
        i.setData(Util.createProfileUri(mCommentsAdapter.getItem(rowId).getAuthor()));
        startActivity(i);
        return true;

    case Constants.DIALOG_EDIT:
        mReplyTargetName = mCommentsAdapter.getItem(rowId).getName();
        mEditTargetBody = mCommentsAdapter.getItem(rowId).getBody();
        showDialog(Constants.DIALOG_EDIT);
        return true;

    case Constants.DIALOG_DELETE:
        mReplyTargetName = mCommentsAdapter.getItem(rowId).getName();
        // It must be a comment, since the OP selftext is reached via options menu, not context menu
        mDeleteTargetKind = Constants.COMMENT_KIND;
        showDialog(Constants.DIALOG_DELETE);
        return true;

    case Constants.DIALOG_REPORT:
        mReportTargetName = mCommentsAdapter.getItem(rowId).getName();
        showDialog(Constants.DIALOG_REPORT);
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}