I know it’s pretty straightforward but I haven’t found any example out there of using the clipboard from Android Applications. So for beginners like me, here is an example of how to copy and paste some text using ClipboardManager object.

This is the Copy button code:
// Copy EditCopy text to the ClipBoard
private void copyToClipBoard()
{
ClipboardManager ClipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipMan.setText(editCopy.getText());
}
and the Paste button source:
// Paste ClipBoard Text to EditPaste
private void pasteFromClipBoard()
{
ClipboardManager ClipMan = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
editPaste.setText(ClipMan.getText());
}
Simple, right?
By the way, editPaste and editCopy are both EditText class objects. In case you need it, the whole project can be downloaded from my GitHub repository.
_______________________________________________________________
Advertisement



I can’t seem to look at this post from my iphone!
Hello,
thanks for sharing your knowledge.
Do u have any idea how can we use this Clipboard functionality for Images.
Thanks
pls reply
Hi Shubham,
Sorry but this week I’ve been pretty busy. Regarding to your question, if you take a look at the ClipboardManager documentation you’ll realize that it can only handle text.
yes that I know..but i can guess, may be this feature can come with new release.