I am developing application where user will copy data in WebView by long pressing on text and then pressing default copy button. Now I want to PASTE that text as soon as user touches EditText. I do have listener on edit text don't know how to past. Need Help.
Asked
Active
Viewed 188 times
3 Answers
0
ClipboardManager mClipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
mEditText.setText(mClipboard.getText());
But, I would strongly recommend you go through the official documentation.

Swayam
- 16,294
- 14
- 64
- 102
-
I cant find getSystemService() eclipse is showing error and quick fix is suggesting create new method getSystemService() – DCoder Apr 21 '14 at 11:56
-
-
In fragment.. Now I am using context.getSystemService(context.CLIPBORD_SERVICE) and its working.. – DCoder Apr 22 '14 at 05:24
-
Yes, because you need to have the context of the Activity to call getSystemService. Great that you figured that out by yourself! Cheers! – Swayam Apr 22 '14 at 06:08
-
1
0
The paste action should be done with this:
https://developer.android.com/reference/android/text/ClipboardManager.html

FillFeile
- 3
- 2
0
Since the accepted answer contains deprecated code... :
private String getClipboardItem() {
String clipboardText = "";
ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
// if the clipboard contain data ...
if (clipboardManager != null && clipboardManager.hasPrimaryClip()) {
ClipData.Item item = clipboardManager.getPrimaryClip().getItemAt(0);
// gets the clipboard as text.
clipboardText = item.getText().toString();
}
return clipboardText;
}

ramon
- 830
- 1
- 12
- 12