We have a web page with an input element on a webview App on Android.
If the input text is not empty, has text, you can touch and the clipboard manager is launched and shows:
BUT, when the input text is empty you can not launch the clipboard manager in order to paste text.
Should I implement onLongClick on Android webview app? if yes, what is the code to simply launch the Android Clipboard Manager?
Should I add an html paste button and solve it with html code?
This is the best solution I have found, just get the text of the clipboard and paste it throug javascript when longclick is done in a focused input of a web page loaded in myWebView
myWebView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip;
clip = clipboard.getPrimaryClip();
String str = clip.getItemAt(0).getText().toString();
myWebView.evaluateJavascript("try{document.activeElement.value='"+str+"';}catch(e){}", new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {}
});
return true;
}
});