1

When I make a call to my WebView and give it a URL I want it to open within the app (i.e. on my page) but it doesn't always do this.

Some pages will open within my app but others will open in the default android web browser.

Here's my code. Any help on this would be much appreciated.

WebView webView = ((WebView)findViewById(R.id.website));
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);     
webView.loadUrl(website);
Goo
  • 1,318
  • 1
  • 13
  • 31
DMCApps
  • 2,110
  • 4
  • 20
  • 36

1 Answers1

2

To override the default behavior, use something like:

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

More or less duplicate of the existing question Clicking URLs opens default browser?

Community
  • 1
  • 1
Integrating Stuff
  • 5,253
  • 2
  • 33
  • 39
  • Awesome works great thanks a lot! I always google around then post on stack overflow ... but I never seem to think of actually doing a search on here :S ... Thanks again! – DMCApps Sep 16 '12 at 18:33