I created app with webview, and i want load all internal links in webview and load external links in android browser. Now problem is I am using html ads and when i click on
I did the some modifications and it is working perfectly for banner ads. I have made following changes:
If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.contains("www.mysite.com"))
{
view.loadUrl(url);
return false;
}else
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
You code should be:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.mysite.com")) {
return true;
}else{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return false;
}
}
All I changed was:
1.) Returning true loads the URL in the webview, no need for view.loadUrl()
2.) Return false when you broadcast the ACTION_VIEW intent