Zach Zach - 1 year ago 383
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

to copy the value, but how would I do this programmatically?

Answer Source

Use ClipboardManager.setPrimaryClip method:

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
ClipData clip = ClipData.newPlainText("label", "Text to copy");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download