Android also has a clipboard (Clipboardmanager) that can copy some useful text to the Clipboard so that the user can paste the place used, below is how to use
Note: When guiding the package
API 11 Before: Android.text.ClipboardManager
After API 11: Android.content.ClipboardManager
Copy CodeThe code is as follows:
/**
* Text copy function is implemented
* Add by Wangqianzhou
* @param content
*/
public static void Copy (String content, context context)
{
Get Clipboard Manager
Clipboardmanager CMB = (Clipboardmanager) context.getsystemservice (Context.clipboard_service);
Cmb.settext (Content.trim ());
}
/**
* Implement Paste function
* Add by Wangqianzhou
* @param context
* @return
*/
public static String paste (context context)
{
Get Clipboard Manager
Clipboardmanager CMB = (Clipboardmanager) context.getsystemservice (Context.clipboard_service);
Return Cmb.gettext (). toString (). Trim ();
}
First create a Clipboardmanager object CMB and associate it with the system Clipboard. You can then copy the contents of the string type to the Clipboard by using the SetText (charsequence text) function. In addition, the Clipboardmanager class provides an abstract charsequence GetText () function and an abstract Boolean hasText (), You can get the contents of the string in the Clipboard, and whether the query Clipboard currently holds content. The Clipboardmanager class has two versions, using only the Clipboard manager that can save strings from API Level 1, since Android 3.0 (API level 11) The new version of the Clipboardmanager class supports more features. Please see the official documentation for details.
android2.1 Previous versions use the following methods
Copy CodeThe code is as follows:
Iclipboard clip = IClipboard.Stub.asInterface (Servicemanager.getservice ("clipboard"));
Clip.getclipboardtext (). toString ();//Get copied content
Clip.setclipboardtext (text);//Set the contents of clipboard
Android implements text copy to clipboard function (Clipboardmanager)