0
votes

There are 2 condition first open all links within App and second is that open all links in mobile browser.

But I want to open web site internal links within App and external link in mobile browser.

For Example: My app is a WebView of https://www.123.com and I am using amazon affiliate links in my web site(https://www.123.com)

Now I want that all links starting with https://www.123.com open within App and all amazon affiliate (external) links starting https://www.amazon.com open in mobile browser.

1

1 Answers

1
votes

Just override shouldOverideURLoading in WebViewClient. You will get the links clicked inside the webview, then process accordingly.

WebView webView = findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        Log.d(TAG, "Request URL is " + request.getUrl());
        if (request.getUrl().toString().equalsIgnoreCase("www.123.com/affiliated")) {
               //DO SOMETHING
        } else {
               //DO SOMETHING
        }
        return super.shouldOverrideUrlLoading(view, request);
    }
});
webView.loadUrl("https://stackoverflow.com/");

Please mark the answer as accepted if it worked.Thanks.