Note: When the guide bag
API 11 Before: Android.text.ClipboardManager
After API 11: Android.content.ClipboardManager
Copy Code code as follows:
/**
* Implement text copy function
* 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. The SetText (charsequence text) function can then be used to copy string content to the Clipboard. In addition, the Clipboardmanager class also provides an abstract charsequence GetText () function and an abstract Boolean hasText (). You can get the contents of the string on the Clipboard and whether the Clipboard is currently saved. There are two versions of the Clipboardmanager class, which uses a clipboard manager that can only save strings from API Level 1, since the Android 3.0 (API level 11 The new version of the Clipboardmanager class supports more features. Please refer to the official documentation for details.
android2.1 Previous versions use the following methods
Copy Code code as follows:
Iclipboard clip = IClipboard.Stub.asInterface (Servicemanager.getservice ("clipboard"));
Clip.getclipboardtext (). toString ();//Get copied content
Clip.setclipboardtext (text);/Set clipboard content