In the browser, you can longClick on URLs. In my WebView, you cannot. How can I make it so you can?
I just wanted to copy URL data on long click.
By taking reference from the accepted answer I wrote this.
registerForContextMenu(webView);
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
WebView webView = (WebView) v;
HitTestResult result = webView.getHitTestResult();
if (result != null) {
if (result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
String linkToCopy = result.getExtra();
copyToClipboard(linkToCopy, AppConstants.URL_TO_COPY);
}
}
}