Last active
June 13, 2016 01:12
-
-
Save cketti/77a3ca308c7528f3fa6febeeedaa0fd0 to your computer and use it in GitHub Desktop.
Activity that copies the URL from the Intent to the clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CopyToClipboardActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Uri uri = getIntent().getData(); | |
if (uri != null) { | |
copyTextToClipboard(uri.toString()); | |
Toast.makeText(this, "Link copied to clipboard", Toast.LENGTH_SHORT).show(); | |
} | |
// Finish right away. We don't want to actually display a UI. | |
finish(); | |
} | |
private void copyTextToClipboard(String url) { | |
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); | |
ClipData clip = ClipData.newPlainText("URL", url); | |
clipboard.setPrimaryClip(clip); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment