I have an Android app in which I'm giving the user a choice to Share the URL to the current page they're viewing. I'm implementing this code as follows:
public static void shareUrl(Context context, String url)
{
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, url);
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, "Share URL via..."));
}
When I call this method, I get a nice popup menu with a list of applications that can open 'text/plain' content, such as email clients and 'messages', see this screenshot.
I would like to add an option to this list, a simple option to copy the URL to the clipboard. Dropbox has such a feature, if you share any file in the public folder via the Dropbox app, you get this same list of app choices but in addition (right at the top) there is a 'Copy link' share option, which copies the link to your clipboard, see this screenshot.
I could just make a separate button on the ActionBar to copy the URL to the user's clipboard, but it fits very well in the Sharing menu in my opinion, and I don't want to waste that space on the ActionBar.
Is it possible to add a sharing option to this menu? How does Dropbox do this? I was thinking perhaps Dropbox has a separate app 'Copy link' that is simply there to receive URLs from Dropbox and copy them to the clipboard, but that makes no sense: (1) where is that app, I can't find it anywhere else on my phone? (2) why do I not get this app as an option when I share via my own app?