There are a lot of copy and paste articles on the Internet, but they are stored in their own programs and do not know how to handle them. Now we can find a feasible method as follows:
Android clipboard (ClipboardManager)
Note: When importing a package
Before API 11: android. text. ClipboardManager
After API 11: android. content. ClipboardManager
Copy codeThe Code is as follows :/**
* Implement text Replication
* @ Param content
*/
Public static void copy (String content, Context context ){
// Obtain the clipboard manager.
ClipboardManager cmb = (ClipboardManager) context
. GetSystemService (Context. CLIPBOARD_SERVICE );
Cmb. setText (content. trim ());
}
Copy codeThe Code is as follows :/**
* Implement the paste Function
*
* @ Param context
* @ Return
*/
Public static String paste (Context context ){
// Obtain the clipboard manager.
ClipboardManager cmb = (ClipboardManager) context
. GetSystemService (Context. CLIPBOARD_SERVICE );
Return cmb. getText (). toString (). trim ();
}
Many articles on the Internet are written in this way:
First: Copy codeThe Code is as follows: private void emulateShiftHeld (KeyEvent. Callback view ){
Try {
KeyEvent shiftPressEvent = new KeyEvent (0, 0, KeyEvent. ACTION_DOWN,
KeyEvent. KEYCODE_SHIFT_LEFT, 0, 0 );
ShiftPressEvent. dispatch (view );
} Catch (Exception e ){
}
}
Second:
Versions later than android2.1
1: (succeeded) Copy codeThe Code is as follows: ClipboardManager clip = (ClipboardManager) getSystemService (Context. CLIPBOARD_SERVICE );
Clip. getText (); // Paste
Clip. setText (str); // copy
Second: Copy codeThe Code is as follows: ClipboardManager c = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE );
C. setText (smsContent. getText (); // set the content of the Clipboard
C. getText (smsContent. getText (); // extract the content of the clipboard
Versions earlier than android2.1Copy codeThe Code is as follows: IClipboard clip = IClipboard. Stub. asInterface (ServiceManager. getService ("clipboard "));
Clip. getClipboardText (). toString (); // obtain the copied content.
Clip. setClipboardText (text); // set the content of the Clipboard