Skip to content

Instantly share code, notes, and snippets.

@cketti
Created June 13, 2016 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cketti/bf1f44cd21beb5061b772be339fd7fa7 to your computer and use it in GitHub Desktop.
Save cketti/bf1f44cd21beb5061b772be339fd7fa7 to your computer and use it in GitHub Desktop.
Share text, but add an additional entry to the Chooser dialog
String url = "https://example.org/cool-link";
// Create Share Intent
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "hey kids check out this cool link\n" + url);
// Create "Copy Link To Clipboard" Intent
Intent clipboardIntent = new Intent(context, CopyToClipboardActivity.class);
clipboardIntent.setData(Uri.parse(url));
// Create Chooser Intent with "Copy Link To Clipboard" option
Intent chooserIntent = Intent.createChooser(shareIntent, "Share with");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { clipboardIntent });
startActivity(chooserIntent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment