1

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.

Swayam
  • 16,294
  • 14
  • 64
  • 102
DCoder
  • 3,486
  • 7
  • 36
  • 68

3 Answers3

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
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