Clipboard for copy and paste option in android

Updated 15 December 2016

Save

Everyone knows the importance of copy and paste in today’s life. Also in many scenarios you have to copy a particular text , image, link etc. in mobile devices as well. Android provide the copy and paste feature through the library of ClipboardManager and ClipData. You can use this library to copy and paste different types of data on your android devices.

For copy you have to make a instance of ClipboardManager and then put the data to be copied on ClipData object then android will put that data onto system wide Clipboard from where you can access that data anywhere in your device. So firstly lets make a ClipData object and add some random data in it like

Now your dummy text is copied to the clipboard you can add a OnLongClickListener on ant text or image then perform all these oprations inside listener. For image the URI is copied on the clipboard.

Now for pasting this dummy text or any other type of data currently in clipboard you have to again instantiate ClipboardManager and then get the data stored/ copied on the clipboard like

Now you have the copied text in String type variable test you can set it anywhere you want. You can again apply OnLongClickListener on any TextView or EditText and set the copied text over there by this method.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home