Android copy and paste shearing function application _android

Source: Internet
Author: User
Tags gettext
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.