A7maDev A7maDev - 4 months ago 35
Android Question

How to add "Add to clipboard" in share intent

How can I add "Add to clipboard" icon in share intent?

I have this code

ClipboardManager copyToClipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Title", "Text");

Intent clipboardIntent = new Intent();
clipboardIntent.putExtra(Intent.EXTRA_TEXT, "Extra Text");
clipboardIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");

Intent shareIntent = new Intent();
shareIntent .setAction(Intent.ACTION_SEND);
shareIntent .putExtra(Intent.EXTRA_TEXT, "Text");
shareIntent .setType("text/plain");

Intent shareChooserIntent = Intent.createChooser(shareIntent, "Share via");
shareChooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { clipboardIntent });

But still missing something, the icon doesnt show in the share intent


You need a actual clipboard application installed which handles the ACTION_SEND intent for text/plain datatypes.

I have seen the icon you talk about show up in the chooser before, but I'm quite sure that it only showed up when I had a custom ROM installed; one that probably had a system application for this purpose. Can you give an example of an application for which the "Copy to Clipboard" option shows up on your device (without a clipboard application installed)?