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.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);/*from   w  ww. jav  a 2 s .  co m*/
    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.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;//from ww  w .  j  a  v a  2 s  .com

    //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)));

}

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 av  a2s  .  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:com.boko.vimusic.ui.activities.AudioPlayerActivity.java

/**
 * /** Used to shared what the user is currently listening to
 *//*from   ww w .j  ava  2  s  . c  o  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:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.settings:
        if (mParameterNode != null) {
            try {
                mParameterNode.setPreferencesFromParameterServer();
            } catch (RuntimeException e) {
                e.printStackTrace();//from  w ww.j a  v  a 2s . c  o  m
            }
        }
        Intent settingsActivityIntent = new Intent(this, SettingsActivity.class);
        settingsActivityIntent.putExtra(getString(R.string.uuids_names_map), mUuidsNamesHashMap);
        startActivityForResult(settingsActivityIntent, StartSettingsActivityRequest.STANDARD_RUN);
        return true;
    case R.id.share:
        mLogger.saveLogToFile();
        Intent shareFileIntent = new Intent(Intent.ACTION_SEND);
        shareFileIntent.setType("text/plain");
        shareFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mLogger.getLogFile()));
        startActivity(shareFileIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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  w ww  .ja  va  2s  .co m*/
        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.googlecode.android_scripting.facade.AndroidFacade.java

@Rpc(description = "Launches an activity that sends an e-mail message to a given recipient.")
public void sendEmail(
        @RpcParameter(name = "to", description = "A comma separated list of recipients.") final String to,
        @RpcParameter(name = "subject") final String subject, @RpcParameter(name = "body") final String body,
        @RpcParameter(name = "attachmentUri") @RpcOptional final String attachmentUri) {
    final Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("plain/text");
    intent.putExtra(android.content.Intent.EXTRA_EMAIL, to.split(","));
    intent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    if (attachmentUri != null) {
        intent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(attachmentUri));
    }/*from ww w .  jav a  2  s.co m*/
    startActivity(intent);
}

From source file:com.wikitude.virtualhome.AugmentedActivity.java

public void shareSnapShot() {

    Log.e(this.getClass().getName(), " VIRTUALHOME: calling captureSnapShot method");

    architectView.captureScreen(ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW,
            new ArchitectView.CaptureScreenCallback() {

                @Override/* ww w.  j  ava2 s.  c o  m*/
                public void onScreenCaptured(final Bitmap screenCapture) {

                    // store screenCapture into external cache directory
                    final File screenCaptureFile = new File(
                            Environment.getExternalStorageDirectory().toString(),
                            "screenCapture_" + System.currentTimeMillis() + ".jpg");

                    // 1. Save bitmap to file & compress to jpeg. You may use PNG too
                    try {
                        final FileOutputStream out = new FileOutputStream(screenCaptureFile);
                        screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out);
                        out.flush();
                        out.close();

                        // 2. create send intent
                        final Intent share = new Intent(Intent.ACTION_SEND);
                        share.setType("image/jpg");
                        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile));

                        // 3. launch intent-chooser
                        final String chooserTitle = "Share Snapshot";
                        startActivity(Intent.createChooser(share, chooserTitle));

                    } catch (final Exception e) {
                        // should not occur when all permissions are set
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Log.e(this.getClass().getName(), " VIRTUALHOME: Share Snapshot failed ");
                                // show toast message in case something went wrong
                                //Toast.makeText(this, " Unexpected error", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
            });
}

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

private void share() {

    if (mUser == null || bcast == null)
        return;/*from  ww w .j  a  v a2  s.  co m*/

    //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, mUser.getFullname() + " live on FlipZu");

    String text = bcast.getText();
    if (text == null) {
        text = mUser.getUsername() + " live on FlipZu";
    }

    //build the body of the message to be shared  
    String shareMessage = text + " - http://fzu.fm/" + bcast.getId();

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

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

}

From source file:com.googlecode.CallerLookup.Main.java

public void doSubmit() {
    String entry = "";
    if (mLookup.getSelectedItemPosition() != 0) {
        entry = mLookup.getSelectedItem().toString() + "\n";
    }/*from   ww  w .j  a  v  a  2 s  .c  om*/

    entry += mURL.getText().toString() + "\n";
    entry += mRegExp.getText().toString() + "\n";

    try {
        String[] mailto = { EMAIL_ADDRESS };
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
        sendIntent.putExtra(Intent.EXTRA_TEXT, entry);
        sendIntent.setType("message/rfc822");
        startActivity(sendIntent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.SubmitFailureTitle);
        alert.setMessage(R.string.SubmitFailureMessage);
        alert.setPositiveButton(android.R.string.ok, null);
        alert.show();
    }
}