Last active
December 17, 2015 14:29
-
-
Save mancdevcarl/5624897 to your computer and use it in GitHub Desktop.
Clipboard programatically
This file contains 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
int currentapiVersion = android.os.Build.VERSION.SDK_INT; | |
if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { | |
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); | |
ClipData clip = ClipData.newPlainText("label", shortUrl); | |
clipboard.setPrimaryClip(clip); | |
Toast toast = Toast.makeText(getApplicationContext(),"copied", Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
} else { | |
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); | |
clipboard.setText(shortUrl); | |
Toast toast = Toast.makeText(getApplicationContext(),"copied", Toast.LENGTH_LONG); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment