Skip to content

Instantly share code, notes, and snippets.

@mancdevcarl
Last active December 17, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mancdevcarl/5624897 to your computer and use it in GitHub Desktop.
Save mancdevcarl/5624897 to your computer and use it in GitHub Desktop.
Clipboard programatically
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