-1

I have created an android app that loads a web page. The app loads page and on clicking any hyper-links on web page, it loads inside the browser of phone. How to avoid this issue?

Rahul Gopi
  • 414
  • 1
  • 16
  • 31
  • possible duplicate of [Android WebView click open within WebView not a default browser](http://stackoverflow.com/questions/9986788/android-webview-click-open-within-webview-not-a-default-browser), or [this one](http://stackoverflow.com/questions/7308904/link-should-be-open-in-same-web-view-in-android), or even [this one](http://stackoverflow.com/questions/4907045/how-to-make-links-open-within-webview-or-open-by-default-browser-depending-on-do)... and probably lots more – musefan May 20 '15 at 12:38

1 Answers1

1

You're going to have to create a custom implementation of the WebViewClient for your WebView. Inside of your WebView Activity, add the following

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

Now, when you initialize your WebView, add the following line

webview.setWebViewClient(new CustomWebViewClient());
Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
Bidhan
  • 10,607
  • 3
  • 39
  • 50