Thursday, February 8, 2018

How to copy text on Clipboard

Android provides a lots of feature, clipboard isone of them.
Android provides a powerful clipboard-based framework for copying and pasting. It supports both simple and complex data types, including text strings, complex data structures, text and binary stream data, and even application assets. Simple text data is stored directly in the clipboard, while complex data is stored as a reference that the pasting application resolves with a content provider. Copying and pasting works both within an application and between applications that implement the framework.

When you use the clipboard framework, you put data into a clip object, and then put the clip object on the system-wide clipboard. The clip object can take one of three forms:

ClipboardManager

In the Android system, the system clipboard is represented by the global ClipboardManager class. You do not instantiate this class directly; instead, you get a reference to it by invoking


ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Simple Text", "Text to Copy");
clipboard.setPrimaryClip(clip);

No comments:

Post a Comment