0

I have an app that opens my webpages in the same intent and within the same webview. Now, I have a certain page that I want it to open in browser when user requests it. Is that possible? Here is my Code:

 WebView myWebView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.getSettings().setAllowFileAccessFromFileURLs(true);
    myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    myWebView.loadUrl("https://mywebpage.me");
    String url = myWebView.getUrl();

myWebView.setWebChromeClient(new WebChromeClient());

and if the user navigates to https//:mywebpage.me/About.html i want it to show in browser.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • See this - https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application – OneCricketeer Apr 16 '18 at 22:13
  • https://stackoverflow.com/questions/33398364/links-are-opening-in-webview-i-want-to-open-in-default-browser-in-android-studio?rq=1 – Viktor Yakunin Apr 16 '18 at 22:35
  • Possible duplicate of [How can I open a URL in Android's web browser from my application?](https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application) – Jhonatan S. Souza Apr 17 '18 at 19:31

1 Answers1

0

You should listen for navigation event.

  1. Create WebViewClient

    private class MyClient extends WebViewClient {
    
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if(url.equals(PUT_YOUR_URL_HERE)) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                return true;
            }  
    
            return false;
        }
    }
    
  2. Pass it to WebView

    myWebView.setWebViewClient(new MyClient());
    

By the way, this method was deprecated in API level 24.

jelic98
  • 723
  • 1
  • 12
  • 28