Zach Zach - 6 months ago 123
Android Question

How to copy text programmatically in my Android app?

I'm building an Android app and I want to copy the text value of an EditText widget. It's possible for the user to press

Menu+A
then
Menu+C
to copy the value, but how would I do this programmatically?

Answer

http://developer.android.com/reference/android/content/ClipboardManager.html

Use ClipboardManager.setPrimaryClip method:

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
ClipData clip = ClipData.newPlainText("label", "Text to copy");
clipboard.setPrimaryClip(clip);
Comments