android copy paste cut function application
- 2020-05-07 20:24:01
- OfStack
There are many copy and paste articles on the Internet, just put their own procedures do not know how to deal with, now find 1 feasible method as follows:
Android clipboard (ClipboardManager)
Note: is used to guide packages
Before API 11: android.text.ClipboardManager
After API 11: android.content.ClipboardManager
Many articles on the Internet say:
type 1:
type 2:
Version after android 2.1
1 :(successfully run)
2:
Version before android 2.1
Android clipboard (ClipboardManager)
Note: is used to guide packages
Before API 11: android.text.ClipboardManager
After API 11: android.content.ClipboardManager
/**
* Achieve text copy function
* @param content
*/
public static void copy(String content, Context context) {
// Get the clipboard manager
ClipboardManager cmb = (ClipboardManager) context
.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText(content.trim());
}
/**
* Paste function
*
* @param context
* @return
*/
public static String paste(Context context) {
// Get the clipboard manager
ClipboardManager cmb = (ClipboardManager) context
.getSystemService(Context.CLIPBOARD_SERVICE);
return cmb.getText().toString().trim();
}
Many articles on the Internet say:
type 1:
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) {
}
}
type 2:
Version after android 2.1
1 :(successfully run)
ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
clip.getText(); // paste
clip.setText(str); // copy
2:
ClipboardManager c= (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
c.setText(smsContent.getText());// Set up the Clipboard The content of the
c.getText(smsContent.getText());// extract clipboard The content of the
Version before android 2.1
IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard"));
clip.getClipboardText().toString();// Get the copied content
clip.setClipboardText(text);// Set up the Clipboard The content of the