Skip to content

Instantly share code, notes, and snippets.

@suryaviyyapu
Created September 7, 2020 17:36
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 suryaviyyapu/fbe84c43b9adc06839d0a15a6ec7da21 to your computer and use it in GitHub Desktop.
Save suryaviyyapu/fbe84c43b9adc06839d0a15a6ec7da21 to your computer and use it in GitHub Desktop.
Android Copy to clipboard Java
TextView textView = findViewById(R.id.text);
String string = textView.getText().toString().trim();
ClipboardManager clipboard = (ClipboardManager)
getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Text", string);
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
Toast.makeText(getApplicationContext(), "Copied!", Toast.LENGTH_SHORT).show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment