Android - fail to call default paste method

2019-08-14 02:36发布

问题:

I made custom contextual action bar in Webview.

And there are copy and paste buttons.

Copy action is working with ClipboardManager.

But pasting method doesn't work.

I referenced this link and problem with setting enabled.

MenuItem mPasteItem = menu.findItem(R.id.menu_paste);
if (!(clipboard.hasPrimaryClip())) {
  mPasteItem.setEnabled(false);
} else if (!(clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {        
    mPasteItem.setEnabled(false);
} else {        
    mPasteItem.setEnabled(true);
}

If I pass setEnabled method, there is no response even "if (pasteData != null) { return;}" called.

Any idea to work this?


EDIT I checked with debug mode, my menu item of pasting operation is setenabled default.

So I think this process(setting enabled) is not necessary.

But Still, paste operation after return; called like below.

pasteData = item.getText();

if (pasteData != null) {
   return;

What is the problem?