There are a lot of copy and paste on the web, just put it in their own program do not know how to deal with, now find a feasible way:
Android's clipboard (Clipboardmanager)
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
* @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 ());
}
Copy Code code as follows:
/**
* Implement Paste function
*
* @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 ();
}
This is how many articles on the Web are written:
First Type:
Copy Code code 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) {
}
}
The second type:
After android2.1 version
One : (successfully run)
Copy Code code as follows:
Clipboardmanager clip = (clipboardmanager) getsystemservice (Context.clipboard_service);
Clip.gettext (); Paste
Clip.settext (str); Copy
secondly:
Copy Code code as follows:
Clipboardmanager c= (Clipboardmanager) Getsystemservice (Clipboard_service);
C.settext (Smscontent.gettext ());//Set the contents of clipboard
C.gettext (Smscontent.gettext ())//Extract clipboard content
android2.1 Previous version
Copy Code code as follows:
Iclipboard clip = IClipboard.Stub.asInterface (Servicemanager.getservice ( "clipboard"));
Clip.getclipboardtext (). toString ()//To get the copied content
Clip.setclipboardtext (text);/Set the contents of the Clipboard