Example usage for android.content Intent createChooser

List of usage examples for android.content Intent createChooser

Introduction

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

Prototype

public static Intent createChooser(Intent target, CharSequence title) 

Source Link

Document

Convenience function for creating a #ACTION_CHOOSER Intent.

Usage

From source file:com.almarsoft.GroundhogReader.MessageActivity.java

private void forwardMessage() {
    String forwardMsg = "\n\n\nForwarded message originally written by "
            + mHeader.getField("From").getBody().trim() + " on the newsgroup [" + mGroup + "]: \n\n"
            + mOriginalText;/*from   w  ww  .ja  v a  2 s .  c  o  m*/

    Intent i = new Intent(Intent.ACTION_SEND);
    i.putExtra(Intent.EXTRA_TEXT, forwardMsg);
    i.putExtra(Intent.EXTRA_SUBJECT, "FWD: " + mSubjectText);
    i.setType("message/rfc822");
    startActivity(Intent.createChooser(i, "Title:"));
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
    case R.id.share:
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = "Check out " + getResources().getString(R.string.theme_name) + " by "
                + getResources().getString(R.string.nicholas_short) + "!\n\nDownload it here!: "
                + getResources().getString(R.string.play_store_link);
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title))));
        break;/*from  w w w. j a v  a2  s.c  om*/

    case R.id.sendemail:
        StringBuilder emailBuilder = new StringBuilder();
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
        if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
            if (!isAppInstalled("com.cyngn.theme.chooser")) {
                if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject));
                } else {
                    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_rro));
                }
            } else {
                intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cos));
            }
        } else {
            intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cm));
        }
        emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "("
                + Build.VERSION.INCREMENTAL + ")");
        emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " (" + Build.VERSION.RELEASE + ") "
                + "[" + Build.ID + "]");
        emailBuilder.append("\nDevice: " + Build.DEVICE);
        emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
        emailBuilder.append("\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")");
        if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
            if (!isAppInstalled("com.cyngn.theme.chooser")) {
                if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                    emailBuilder.append("\nTheme Engine: Not Available");
                } else {
                    emailBuilder.append("\nTheme Engine: Layers Manager (RRO)");
                }
            } else {
                emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine");
            }
        } else {
            emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine");
        }
        PackageInfo appInfo = null;
        try {
            appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        emailBuilder.append("\nApp Version Name: " + appInfo.versionName);
        emailBuilder.append("\nApp Version Code: " + appInfo.versionCode);

        intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
        startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title))));
        break;

    case R.id.changelog:
        changelog();
        break;

    case R.id.hide_launcher:
        boolean checked = item.isChecked();
        if (!checked) {
            new MaterialDialog.Builder(this).title(R.string.warning).content(R.string.hide_action)
                    .positiveText(R.string.nice).show();
        }
        item.setChecked(!checked);
        setLauncherIconEnabled(checked);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.anjalimacwan.fragment.NoteEditFragment.java

public void dispatchKeyShortcutEvent(int keyCode) {
    switch (keyCode) {

    // CTRL+S: Save
    case KeyEvent.KEYCODE_S:
        // Set current note contents to a String
        contents = noteContents.getText().toString();

        // If EditText is empty, show toast informing user to enter some text
        if (contents.equals(""))
            showToast(R.string.empty_note);
        else {/*from   ww  w  . j  a va2 s.  co  m*/
            try {
                // Keyboard shortcut just saves the note; no dialog shown
                saveNote();
                isSavedNote = true;

                // Change window title
                String title;
                try {
                    title = listener.loadNoteTitle(filename);
                } catch (IOException e) {
                    title = getResources().getString(R.string.edit_note);
                }

                getActivity().setTitle(title);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title,
                            null, ContextCompat.getColor(getActivity(), R.color.primary));
                    getActivity().setTaskDescription(taskDescription);
                }
            } catch (IOException e) {
                // Show error message as toast if file fails to save
                showToast(R.string.failed_to_save);
            }
        }
        break;

    // CTRL+D: Delete
    case KeyEvent.KEYCODE_D:
        listener.showDeleteDialog();
        break;

    // CTRL+H: Share
    case KeyEvent.KEYCODE_H:
        // Set current note contents to a String
        contents = noteContents.getText().toString();

        // If EditText is empty, show toast informing user to enter some text
        if (contents.equals(""))
            showToast(R.string.empty_note);
        else {
            // Send a share intent
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, contents);
            shareIntent.setType("text/plain");

            // Verify that the intent will resolve to an activity, and send
            if (shareIntent.resolveActivity(getActivity().getPackageManager()) != null)
                startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
        }
        break;
    }
}

From source file:com.boko.vimusic.ui.activities.AudioPlayerActivity.java

/**
 * /** Used to shared what the user is currently listening to
 *//*w w w.  j  a v a2  s  .  c om*/
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: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  ww w  .j  a va 2  s  .c om*/
        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.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 w  ww  .  j  av a2  s.  c  o  m*/

    //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"/*w w  w .j  a  v a  2s  .c  om*/
 *
 * "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.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//  w  w w.  ja  va2  s  . co 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;/* www  .j av  a 2  s  .c  o 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.ryan.ryanreader.fragments.CommentListingFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info.position <= 0)
        return false;

    final Action action = Action.values()[item.getItemId()];
    final RedditPreparedComment comment = (RedditPreparedComment) lv.getAdapter().getItem(info.position);

    switch (action) {

    case UPVOTE:/*from  ww  w . j a  va 2  s  .  c  om*/
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UPVOTE);
        break;

    case DOWNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.DOWNVOTE);
        break;

    case UNVOTE:
        comment.action(getSupportActivity(), RedditAPI.RedditAction.UNVOTE);
        break;

    case REPORT:

        new AlertDialog.Builder(getSupportActivity()).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int which) {
                        comment.action(getSupportActivity(), RedditAPI.RedditAction.REPORT);
                        // TODO update the view to show the result
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(getSupportActivity(), CommentReplyActivity.class);
        intent.putExtra("parentIdAndType", comment.idAndType);
        startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(getSupportActivity(), CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.idAndType);
        intent.putExtra("commentText", comment.src.body);
        startActivity(intent);
        break;
    }

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

        if (linksInComment.isEmpty()) {
            General.quickToast(getSupportActivity(), 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(getSupportActivity());
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(getSupportActivity(), 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.src.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.src.body));
        startActivityForResult(Intent.createChooser(mailer, context.getString(R.string.action_share)), 1);

        break;

    case COPY:

        ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.src.body));
        break;

    case COLLAPSE:
        if (comment.getBoundView() != null)
            handleCommentVisibilityToggle(comment.getBoundView());
        break;

    case USER_PROFILE:
        UserProfileDialog.newInstance(comment.src.author).show(getSupportActivity());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment.src).show(getSupportActivity());
        break;

    }

    return true;
}