The source code of a sample application demonstrating all of this can be found on GitHub. For all the other times, when it’s just the URL they’re after, the Copy link to clipboard option is right there at the top. ![]() Maybe sometimes this is just what your users want. And it stills copies all of the text to the clipboard. Of course there’s still the “Copy to clipboard” provided by the Drive app. Using the Theme.NoDisplay theme disables the activity transition animation when our short-lived Activity is launched.Īnd here is what it looks like to the user: ![]() The icon and label we give CopyToClipboardActivity in the app manifest are the ones being used by the Chooser dialog when displaying our custom entry. Then we finish the Activity right away to return to the screen where the Share event originated. In onCreate() we simply get the URL from the Intent that started the Activity and copy it to the clipboard. In this case we point to an the Activity CopyToClipboardActivity that we still need to define. Using EXTRA_INITIAL_INTENTS we can pass in a list of Intents that will be added to the Chooser dialog. To make this work, we slightly modify the Share snippet from before. While all regular Share targets receive the link and additional text. So let’s add a Copy link to clipboard entry that does just that. Option 3: Extend the Share dialogįortunately, it’s easy enough to add your own action to the Share dialog. By now users know that Copy to Clipboard can be found in the Share dialog and don’t necessarily look elsewhere. However, this can lead to a confusing user experience. Getting only the link is easy enough, while sharing uses additional text to provide some context. Twitter, for example, added a “Copy link to Tweet” entry to its menu.įunctionality-wise this should make most users happy. Option 2: Don’t shareĪ possible way around this situation is to not use the Share facility and instead provide another way to copy a link to the clipboard. And that’s the reason why most apps provide this additional text. In that case the headline and a short excerpt would surely be much appreciated by the recipient. But let’s say you want to send a link to a news article to a friend. This way only the URL ends up in the clipboard when Copy to Clipboard is selected. The simplest way to satisfy the original request is to put only the URL into EXTRA_TEXT extra of the Share Intent. So the easiest solution, sharing only the URL when the user selects Copy to clipboard, is not really feasible. The Copy to clipboard action is part of the Google Drive app and was only added at the end of 2012.Īnd of course there exist many more applications that provide the same functionality. What many people probably don’t know is that this is not a feature built into the Android platform. Copy to ClipboardĪs you can see in the image below “Copy to clipboard” is an option in the list of available Share targets. createChooser ( shareIntent, "Share with" )) Īnd that’s about all app developers have to do in order to show the Share dialog. ![]() EXTRA_TEXT, "hey kids check out this cool link\n" "" ) startActivity ( Intent. Intent shareIntent = new Intent () shareIntent.
0 Comments
Leave a Reply. |