user691285
user691285

Reputation: 401

How to select which URL should redirect to Android browser from WebView?

I have a WebView and I load a web page in to it. I want to choose which link's on that page should open in WebView and which should open in Android browser. I can make them all open in WebView by using WebViewClient and overriding shouldOverrideUrlLoading(...). I have tried something like:

public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (url.toLowerCase().contains("yahoo.com")) {
            return false;
        } else {

            view.loadUrl(url);
            return true;
        }
         }   

,but that is not working. Any Ideas how to do this ?

Upvotes: 0

Views: 363

Answers (1)

jawsware
jawsware

Reputation: 934

The documentation is not completely clear:

If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

I'm assuming WebViewClient refers to the WebView view parameter.

I would try returning true and firing a new intent to handle the url.

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse(url));

startActivity(intent);

return true;

Upvotes: 1

Related Questions