Issue
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
}
}
Solution
shouldOverrideUrlLoading
method of WebViewClient
will do the trick.
yourWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Load the url in your own webView. or pass the url to another activity. and stop the current loading. check the following pages
}
}
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/
Answered By - Shaiful
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.