I am having some html code which i am displaying in Webview, it has a read more link in it on click of which it takes me to default browser. But i want to change this behavior and open that link in different activity, for which i want to detect the click on that link within the HTML code. I tried the following code but to no avail.
Inside onCreate
registerForContextMenu(w);
and after that
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
WebView.HitTestResult result = w.getHitTestResult();
System.out.println("asdasfdf");
if (result.getType() == HitTestResult.ANCHOR_TYPE
|| result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
System.out.println("#%@#%$%");
// set the header title to the link url
}
}
shouldOverrideUrlLoadingmethod ofWebViewClientwill do the trick.You’ll get the clicked url in second parameter.
Check this link for more detail.
WebViewClient (shouldOverrideUrlLoading)
http://www.catchingtales.com/android-webview-shouldoverrideurlloading-and-redirect/416/