Android WebView click open within WebView not a default browser

Solution 1:

You have to set up a webViewClient for your webView.

Sample:

this.mWebView.setWebViewClient(new WebViewClient(){

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url){
      view.loadUrl(url);
      return true;
    }
});

Solution 2:

You need to set up a WebViewClient in order to override that behavior (opening links using the web browser). You obviously have your WebView declared, but then set up a WebViewClient like so:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

Then you need to define your WebViewClient():

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.example.com")) {
            // Designate Urls that you want to load in WebView still.
            return false;
        }

        // Otherwise, give the default behavior (open in browser)
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
}

Then start your WebViewClient:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new MyWebViewClient());

http://developer.android.com/guide/webapps/webview.html

Solution 3:

I face same problem and i just fixed it by adding single line.

webview.setWebViewClient(new WebViewClient());

and this solved my problem.

Solution 4:

You need to call wvBikeSite.setWebViewClient, e.g:

    MyWebViewClient wvc = new MyWebViewClient();
    wvBikeSite.setWebViewClient(wvc);

Where MyWebViewClient overrides shouldOverrideUrlLoading, viz:

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}